Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ember Engine Setup for Secrets Sync #23653

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ui/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ export default class App extends Application {
},
},
},
sync: {
dependencies: {
services: ['router', 'store', 'flash-messages'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure we want to include namespace here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added a few services here we would be using for sure and anything else can be added as needed. Saves from having some services shared that we might not be accessing.

},
},
};
}

Expand Down
3 changes: 3 additions & 0 deletions ui/app/components/sidebar/nav/cluster.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
@text="Secrets engines"
data-test-sidebar-nav-link="Secrets engines"
/>
{{#if this.version.isEnterprise}}
<Nav.Link @route="vault.cluster.sync" @text="Secrets sync" data-test-sidebar-nav-link="Secrets sync" />
{{/if}}
{{#if (has-permission "access")}}
<Nav.Link
@route={{get (route-params-for "access") "route"}}
Expand Down
1 change: 1 addition & 0 deletions ui/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Router.map(function () {
this.route('vault', { path: '/' }, function () {
this.route('cluster', { path: '/:cluster_name' }, function () {
this.route('dashboard');
this.mount('sync');
this.route('oidc-provider-ns', { path: '/*namespace/identity/oidc/provider/:provider_name/authorize' });
this.route('oidc-provider', { path: '/identity/oidc/provider/:provider_name/authorize' });
this.route('oidc-callback', { path: '/auth/*auth_path/oidc/callback' });
Expand Down
11 changes: 11 additions & 0 deletions ui/docs/ember-engines.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ loadInitializers(App, config.modulePrefix);

If you used `ember g in-repo-engine <engine-name>` to generate the engine’s blueprint, it should have added `this.mount(<engine-name>)` to the main app’s `router.js` file (this adds your engine and its associated routes). \*Move `this.mount(<engine-name>)` to match your engine’s route structure. For more information about [Routable Engines](https://ember-engines.com/docs/quickstart#routable-engines).

## Add engine path to ember-addon section of main app package.json

```json
"ember-addon": {
"paths": [
"lib/core",
"lib/your-new-engine"
]
},
```

### Important Notes:

- Anytime a new engine is created, you will need to `yarn install` and **RESTART** ember server!
Expand Down
22 changes: 22 additions & 0 deletions ui/lib/sync/addon/engine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

import Engine from 'ember-engines/engine';
import loadInitializers from 'ember-load-initializers';
import Resolver from 'ember-resolver';
import config from './config/environment';

const { modulePrefix } = config;

export default class SyncEngine extends Engine {
modulePrefix = modulePrefix;
Resolver = Resolver;
dependencies = {
services: ['router', 'store', 'flash-messages'],
externalRoutes: [],
};
}

loadInitializers(SyncEngine, modulePrefix);
24 changes: 24 additions & 0 deletions ui/lib/sync/addon/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

import buildRoutes from 'ember-engines/routes';

export default buildRoutes(function () {
this.route('secrets', function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nesting within the secrets/ route in case syncing expands to other resources

this.route('overview');
this.route('destinations', function () {
this.route('create', function () {
this.route('destination', { path: '/:type' });
});
this.route('destination', { path: '/:type/:name' }, function () {
this.route('edit');
this.route('details');
this.route('secrets', function () {
this.route('sync');
});
});
});
});
});
17 changes: 17 additions & 0 deletions ui/lib/sync/addon/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

import type RouterService from '@ember/routing/router-service';

export default class SyncSecretsRoute extends Route {
@service declare readonly router: RouterService;

redirect() {
this.router.transitionTo('vault.cluster.sync.secrets.overview');
}
}
16 changes: 16 additions & 0 deletions ui/lib/sync/config/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

/* eslint-env node */
'use strict';

module.exports = function (environment) {
const ENV = {
modulePrefix: 'sync',
environment,
};

return ENV;
};
22 changes: 22 additions & 0 deletions ui/lib/sync/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

/* eslint-env node */
/* eslint-disable n/no-extraneous-require */
'use strict';

const { buildEngine } = require('ember-engines/lib/engine-addon');

module.exports = buildEngine({
name: 'sync',

lazyLoading: Object.freeze({
enabled: false,
}),

isDevelopingAddon() {
return true;
},
});
29 changes: 29 additions & 0 deletions ui/lib/sync/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "sync",
"keywords": [
"ember-addon",
"ember-engine"
],
"dependencies": {
"@hashicorp/design-system-components": "*",
"ember-cli-htmlbars": "*",
"ember-cli-babel": "*",
"ember-concurrency": "*",
"@ember/test-waiters": "*",
"ember-cli-typescript": "*",
"@types/ember": "latest",
"@types/ember-data": "latest",
"@types/ember-data__store": "latest",
"@types/ember__array": "latest",
"@types/ember__component": "latest",
"@types/ember__controller": "latest",
"@types/ember__engine": "latest",
"@types/ember__routing": "latest",
"@types/rsvp": "latest"
},
"ember-addon": {
"paths": [
"../core"
]
}
}
3 changes: 2 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@
"lib/open-api-explorer",
"lib/pki",
"lib/replication",
"lib/service-worker-authenticated-download"
"lib/service-worker-authenticated-download",
"lib/sync"
]
},
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions ui/tests/acceptance/enterprise-sidebar-nav-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ module('Acceptance | Enterprise | sidebar navigation', function (hooks) {
test('it should render enterprise only navigation links', async function (assert) {
assert.dom(panel('Cluster')).exists('Cluster nav panel renders');

await click(link('Secrets sync'));
assert.strictEqual(currentURL(), '/vault/sync/secrets/overview', 'Sync route renders');

await click(link('Replication'));
assert.strictEqual(currentURL(), '/vault/replication', 'Replication route renders');
await click('[data-test-replication-enable]');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module('Integration | Component | sidebar-nav-cluster', function (hooks) {
const links = [
'Dashboard',
'Secrets engines',
'Secrets sync',
'Access',
'Policies',
'Tools',
Expand Down
3 changes: 3 additions & 0 deletions ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
"service-worker-authenticated-download/test-support/*": [
"lib/service-worker-authenticated-download/addon-test-support/*"
],
"sync": ["lib/sync/addon"],
"sync/*": ["lib/sync/addon/*"],
"*": ["types/*"]
}
},
Expand All @@ -84,6 +86,7 @@
"lib/pki/**/*",
"lib/replication/**/*",
"lib/service-worker-authenticated-download/**/*",
"lib/sync/**/*",
"mirage/**/*"
],
"exclude": ["node_modules"]
Expand Down