Skip to content

Commit

Permalink
UI: PKI routes extend base Route (#20179)
Browse files Browse the repository at this point in the history
  • Loading branch information
hashishaw authored Apr 17, 2023
1 parent 17a2827 commit d518846
Show file tree
Hide file tree
Showing 28 changed files with 142 additions and 99 deletions.
16 changes: 13 additions & 3 deletions ui/lib/pki/addon/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@

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

export default class PkiRoute extends Route {
@service pathHelp;
@service secretMountPath;

beforeModel() {
// Must call this promise before the model hook otherwise the model doesn't hydrate from OpenAPI correctly.
// only needs to be called once to add the openAPI attributes to the model prototype
return this.pathHelp.getNewModel('pki/role', this.secretMountPath.currentPath);
// We call pathHelp for all the models in this engine that use OpenAPI before any model hooks
// so that the model attributes hydrate correctly. These only need to be called once to add
// the openAPI attributes to the model prototype
const mountPath = this.secretMountPath.currentPath;
return hash({
role: this.pathHelp.getNewModel('pki/role', mountPath),
urls: this.pathHelp.getNewModel('pki/urls', mountPath),
key: this.pathHelp.getNewModel('pki/key', mountPath),
signCsr: this.pathHelp.getNewModel('pki/sign-intermediate', mountPath),
certGenerate: this.pathHelp.getNewModel('pki/certificate/generate', mountPath),
certSign: this.pathHelp.getNewModel('pki/certificate/sign', mountPath),
});
}
}
4 changes: 2 additions & 2 deletions ui/lib/pki/addon/routes/certificates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class PkiCertificatesIndexRoute extends Route {
super.setupController(controller, resolvedModel);
const certificates = resolvedModel.certificates;

if (certificates?.length) controller.message = getCliMessage('certificates');
else controller.message = getCliMessage();
if (certificates?.length) controller.notConfiguredMessage = getCliMessage('certificates');
else controller.notConfiguredMessage = getCliMessage();
}
}
6 changes: 0 additions & 6 deletions ui/lib/pki/addon/routes/configuration/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ import { hash } from 'rsvp';
export default class PkiConfigurationCreateRoute extends Route {
@service secretMountPath;
@service store;
@service pathHelp;

beforeModel() {
// pki/urls uses openApi to hydrate model
return this.pathHelp.getNewModel('pki/urls', this.secretMountPath.currentPath);
}

model() {
return hash({
Expand Down
3 changes: 0 additions & 3 deletions ui/lib/pki/addon/routes/configuration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { withConfig } from 'pki/decorators/check-config';
import { hash } from 'rsvp';
import { PKI_DEFAULT_EMPTY_STATE_MSG } from 'pki/routes/overview';

@withConfig()
export default class ConfigurationIndexRoute extends Route {
Expand Down Expand Up @@ -53,7 +52,5 @@ export default class ConfigurationIndexRoute extends Route {

setupController(controller, resolvedModel) {
super.setupController(controller, resolvedModel);

controller.message = PKI_DEFAULT_EMPTY_STATE_MSG;
}
}
15 changes: 12 additions & 3 deletions ui/lib/pki/addon/routes/issuers/generate-intermediate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@
* SPDX-License-Identifier: MPL-2.0
*/

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { withConfirmLeave } from 'core/decorators/confirm-leave';
import PkiIssuersIndexRoute from '.';

@withConfirmLeave()
export default class PkiIssuersGenerateIntermediateRoute extends PkiIssuersIndexRoute {
export default class PkiIssuersGenerateIntermediateRoute extends Route {
@service store;
@service secretMountPath;

model() {
return this.store.createRecord('pki/action', { actionType: 'generate-csr' });
}

setupController(controller, resolvedModel) {
super.setupController(controller, resolvedModel);
controller.breadcrumbs.push({ label: 'generate CSR' });
controller.breadcrumbs = [
{ label: 'secrets', route: 'secrets', linkExternal: true },
{ label: this.secretMountPath.currentPath, route: 'overview' },
{ label: 'issuers', route: 'issuers.index' },
{ label: 'generate CSR' },
];
}
}
12 changes: 9 additions & 3 deletions ui/lib/pki/addon/routes/issuers/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
* SPDX-License-Identifier: MPL-2.0
*/

import PkiIssuersIndexRoute from '.';
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { withConfirmLeave } from 'core/decorators/confirm-leave';

@withConfirmLeave()
export default class PkiIssuersImportRoute extends PkiIssuersIndexRoute {
export default class PkiIssuersImportRoute extends Route {
@service store;
@service secretMountPath;

model() {
return this.store.createRecord('pki/action');
}

setupController(controller, resolvedModel) {
super.setupController(controller, resolvedModel);
controller.breadcrumbs.push({ label: 'import' });
controller.breadcrumbs = [
{ label: 'secrets', route: 'secrets', linkExternal: true },
{ label: this.secretMountPath.currentPath, route: 'overview' },
{ label: 'issuers', route: 'issuers.index' },
{ label: 'import' },
];
}
}
8 changes: 1 addition & 7 deletions ui/lib/pki/addon/routes/issuers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import { PKI_DEFAULT_EMPTY_STATE_MSG } from 'pki/routes/overview';
export default class PkiIssuersListRoute extends Route {
@service store;
@service secretMountPath;
@service pathHelp;

beforeModel() {
// Must call this promise before the model hook otherwise it doesn't add OpenApi to record.
return this.pathHelp.getNewModel('pki/issuer', this.secretMountPath.currentPath);
}

model() {
return this.store
Expand All @@ -39,6 +33,6 @@ export default class PkiIssuersListRoute extends Route {
{ label: this.secretMountPath.currentPath, route: 'overview' },
{ label: 'issuers', route: 'issuers.index' },
];
controller.message = PKI_DEFAULT_EMPTY_STATE_MSG;
controller.notConfiguredMessage = PKI_DEFAULT_EMPTY_STATE_MSG;
}
}
9 changes: 6 additions & 3 deletions ui/lib/pki/addon/routes/issuers/issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
* SPDX-License-Identifier: MPL-2.0
*/

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

export default class PkiIssuerIndexRoute extends Route {
@service store;
@service secretMountPath;

// Single issuer index route extends issuers list route
export default class PkiIssuerIndexRoute extends PkiIssuersListRoute {
model() {
const { issuer_ref } = this.paramsFor('issuers/issuer');
return this.store.queryRecord('pki/issuer', {
Expand Down
22 changes: 17 additions & 5 deletions ui/lib/pki/addon/routes/issuers/issuer/cross-sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@
* SPDX-License-Identifier: MPL-2.0
*/

import PkiIssuerRoute from '../issuer';
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { withConfirmLeave } from 'core/decorators/confirm-leave';

@withConfirmLeave()
export default class PkiIssuerCrossSignRoute extends PkiIssuerRoute {
export default class PkiIssuerCrossSignRoute extends Route {
@service store;
@service secretMountPath;

model() {
return this.modelFor('issuers.issuer');
}

setupController(controller, resolvedModel) {
super.setupController(controller, resolvedModel);
controller.breadcrumbs.push(

controller.breadcrumbs = [
{ label: 'secrets', route: 'secrets', linkExternal: true },
{ label: this.secretMountPath.currentPath, route: 'overview' },
{ label: 'issuers', route: 'issuers.index' },
{ label: resolvedModel.id, route: 'issuers.issuer.details' },
{ label: 'cross-sign' }
);
{ label: 'cross-sign' },
];
}
}
16 changes: 13 additions & 3 deletions ui/lib/pki/addon/routes/issuers/issuer/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
* SPDX-License-Identifier: MPL-2.0
*/

import PkiIssuerRoute from '../issuer';
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { verifyCertificates } from 'vault/utils/parse-pki-cert';
import { hash } from 'rsvp';
export default class PkiIssuerDetailsRoute extends PkiIssuerRoute {

export default class PkiIssuerDetailsRoute extends Route {
@service store;
@service secretMountPath;

model() {
const issuer = this.modelFor('issuers.issuer');
return hash({
Expand All @@ -19,7 +24,12 @@ export default class PkiIssuerDetailsRoute extends PkiIssuerRoute {

setupController(controller, resolvedModel) {
super.setupController(controller, resolvedModel);
controller.breadcrumbs.push({ label: resolvedModel.issuer.id });
controller.breadcrumbs = [
{ label: 'secrets', route: 'secrets', linkExternal: true },
{ label: this.secretMountPath.currentPath, route: 'overview' },
{ label: 'issuers', route: 'issuers.index' },
{ label: resolvedModel.issuer.id },
];
}

/**
Expand Down
6 changes: 0 additions & 6 deletions ui/lib/pki/addon/routes/issuers/issuer/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ import { withConfirmLeave } from 'core/decorators/confirm-leave';
export default class PkiIssuerEditRoute extends Route {
@service store;
@service secretMountPath;
@service pathHelp;

beforeModel() {
// Must call this promise before the model hook otherwise it doesn't add OpenApi to record.
return this.pathHelp.getNewModel('pki/issuer', this.secretMountPath.currentPath);
}

model() {
const { issuer_ref } = this.paramsFor('issuers/issuer');
Expand Down
4 changes: 2 additions & 2 deletions ui/lib/pki/addon/routes/issuers/issuer/rotate-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* SPDX-License-Identifier: MPL-2.0
*/

import PkiIssuerRoute from '../issuer';
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { hash } from 'rsvp';
import { parseCertificate } from 'vault/utils/parse-pki-cert';
import camelizeKeys from 'vault/utils/camelize-object-keys';
import { withConfirmLeave } from 'core/decorators/confirm-leave';

@withConfirmLeave('model.newRootModel')
export default class PkiIssuerRotateRootRoute extends PkiIssuerRoute {
export default class PkiIssuerRotateRootRoute extends Route {
@service secretMountPath;
@service store;

Expand Down
6 changes: 0 additions & 6 deletions ui/lib/pki/addon/routes/issuers/issuer/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ import { withConfirmLeave } from 'core/decorators/confirm-leave';
export default class PkiIssuerSignRoute extends Route {
@service store;
@service secretMountPath;
@service pathHelp;

beforeModel() {
// Must call this promise before the model hook otherwise it doesn't add OpenApi to record.
return this.pathHelp.getNewModel('pki/sign-intermediate', this.secretMountPath.currentPath);
}

model() {
const { issuer_ref } = this.paramsFor('issuers/issuer');
Expand Down
12 changes: 9 additions & 3 deletions ui/lib/pki/addon/routes/keys/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
* SPDX-License-Identifier: MPL-2.0
*/

import PkiKeysIndexRoute from '.';
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { withConfirmLeave } from 'core/decorators/confirm-leave';

@withConfirmLeave()
export default class PkiKeysCreateRoute extends PkiKeysIndexRoute {
export default class PkiKeysCreateRoute extends Route {
@service secretMountPath;
@service store;

model() {
Expand All @@ -17,6 +18,11 @@ export default class PkiKeysCreateRoute extends PkiKeysIndexRoute {

setupController(controller, resolvedModel) {
super.setupController(controller, resolvedModel);
controller.breadcrumbs.push({ label: 'generate' });
controller.breadcrumbs = [
{ label: 'secrets', route: 'secrets', linkExternal: true },
{ label: this.secretMountPath.currentPath, route: 'overview' },
{ label: 'keys', route: 'keys.index' },
{ label: 'generate' },
];
}
}
12 changes: 9 additions & 3 deletions ui/lib/pki/addon/routes/keys/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
* SPDX-License-Identifier: MPL-2.0
*/

import PkiKeysIndexRoute from '.';
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { withConfirmLeave } from 'core/decorators/confirm-leave';

@withConfirmLeave()
export default class PkiKeysImportRoute extends PkiKeysIndexRoute {
export default class PkiKeysImportRoute extends Route {
@service secretMountPath;
@service store;

model() {
Expand All @@ -17,6 +18,11 @@ export default class PkiKeysImportRoute extends PkiKeysIndexRoute {

setupController(controller, resolvedModel) {
super.setupController(controller, resolvedModel);
controller.breadcrumbs.push({ label: 'import' });
controller.breadcrumbs = [
{ label: 'secrets', route: 'secrets', linkExternal: true },
{ label: this.secretMountPath.currentPath, route: 'overview' },
{ label: 'keys', route: 'keys.index' },
{ label: 'import' },
];
}
}
10 changes: 2 additions & 8 deletions ui/lib/pki/addon/routes/keys/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@ import { PKI_DEFAULT_EMPTY_STATE_MSG } from 'pki/routes/overview';

@withConfig()
export default class PkiKeysIndexRoute extends Route {
@service store;
@service secretMountPath;
@service pathHelp;

beforeModel() {
// Must call this promise before the model hook otherwise it doesn't add OpenApi to record.
return this.pathHelp.getNewModel('pki/key', this.secretMountPath.currentPath);
}
@service store;

model() {
return hash({
Expand All @@ -41,6 +35,6 @@ export default class PkiKeysIndexRoute extends Route {
{ label: this.secretMountPath.currentPath, route: 'overview' },
{ label: 'keys', route: 'keys.index' },
];
controller.message = PKI_DEFAULT_EMPTY_STATE_MSG;
controller.notConfiguredMessage = PKI_DEFAULT_EMPTY_STATE_MSG;
}
}
8 changes: 6 additions & 2 deletions ui/lib/pki/addon/routes/keys/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
* SPDX-License-Identifier: MPL-2.0
*/

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

export default class PkiKeyRoute extends Route {
@service secretMountPath;
@service store;

export default class PkiKeyRoute extends PkiKeysIndexRoute {
model() {
const { key_id } = this.paramsFor('keys/key');
return this.store.queryRecord('pki/key', {
Expand Down
17 changes: 14 additions & 3 deletions ui/lib/pki/addon/routes/keys/key/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@
* SPDX-License-Identifier: MPL-2.0
*/

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

export default class PkiKeyDetailsRoute extends PkiKeyRoute {
export default class PkiKeyDetailsRoute extends Route {
@service secretMountPath;

model() {
return this.modelFor('keys.key');
}
setupController(controller, resolvedModel) {
super.setupController(controller, resolvedModel);
controller.breadcrumbs.push({ label: resolvedModel.id });
controller.breadcrumbs = [
{ label: 'secrets', route: 'secrets', linkExternal: true },
{ label: this.secretMountPath.currentPath, route: 'overview' },
{ label: 'keys', route: 'keys.index' },
{ label: resolvedModel.id },
];
}
}
Loading

0 comments on commit d518846

Please sign in to comment.