UI: PKI routes extend base Route (#20179)

This commit is contained in:
Chelsea Shaw 2023-04-17 10:58:30 -05:00 committed by GitHub
parent ef7dd8c1bb
commit dfbd9091b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 142 additions and 99 deletions

View File

@ -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),
});
}
}

View File

@ -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();
}
}

View File

@ -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({

View File

@ -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 {
@ -53,7 +52,5 @@ export default class ConfigurationIndexRoute extends Route {
setupController(controller, resolvedModel) {
super.setupController(controller, resolvedModel);
controller.message = PKI_DEFAULT_EMPTY_STATE_MSG;
}
}

View File

@ -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' },
];
}
}

View File

@ -3,13 +3,14 @@
* 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');
@ -17,6 +18,11 @@ export default class PkiIssuersImportRoute extends PkiIssuersIndexRoute {
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' },
];
}
}

View File

@ -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
@ -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;
}
}

View File

@ -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', {

View File

@ -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' },
];
}
}

View File

@ -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({
@ -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 },
];
}
/**

View File

@ -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');

View File

@ -3,7 +3,7 @@
* 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';
@ -11,7 +11,7 @@ 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;

View File

@ -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');

View File

@ -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() {
@ -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' },
];
}
}

View File

@ -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() {
@ -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' },
];
}
}

View File

@ -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({
@ -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;
}
}

View File

@ -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', {

View File

@ -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 },
];
}
}

View File

@ -4,12 +4,24 @@
*/
import { withConfirmLeave } from 'core/decorators/confirm-leave';
import PkiKeyRoute from '../key';
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
@withConfirmLeave()
export default class PkiKeyEditRoute extends PkiKeyRoute {
export default class PkiKeyEditRoute extends Route {
@service secretMountPath;
model() {
return this.modelFor('keys.key');
}
setupController(controller, resolvedModel) {
super.setupController(controller, resolvedModel);
controller.breadcrumbs.push({ label: resolvedModel.id, route: 'keys.key.details' }, { label: 'edit' });
controller.breadcrumbs = [
{ label: 'secrets', route: 'secrets', linkExternal: true },
{ label: this.secretMountPath.currentPath, route: 'overview' },
{ label: 'keys', route: 'keys.index' },
{ label: resolvedModel.id },
];
}
}

View File

@ -62,10 +62,11 @@ export default class PkiOverviewRoute extends Route {
const roles = resolvedModel.roles;
const certificates = resolvedModel.certificates;
controller.message = getCliMessage();
controller.notConfiguredMessage = getCliMessage();
if (roles?.length) controller.message = getCliMessage('roles');
if (certificates?.length) controller.message = getCliMessage('certificates');
if (roles?.length && certificates?.length) controller.message = getCliMessage('roles and certificates');
if (roles?.length) controller.notConfiguredMessage = getCliMessage('roles');
if (certificates?.length) controller.notConfiguredMessage = getCliMessage('certificates');
if (roles?.length && certificates?.length)
controller.notConfiguredMessage = getCliMessage('roles and certificates');
}
}

View File

@ -37,7 +37,7 @@ export default class PkiRolesIndexRoute extends Route {
super.setupController(controller, resolvedModel);
const roles = resolvedModel.roles;
if (roles?.length) controller.message = getCliMessage('roles');
else controller.message = getCliMessage();
if (roles?.length) controller.notConfiguredMessage = getCliMessage('roles');
else controller.notConfiguredMessage = getCliMessage();
}
}

View File

@ -11,13 +11,6 @@ withConfirmLeave();
export default class PkiRoleGenerateRoute extends Route {
@service store;
@service secretMountPath;
@service pathHelp;
beforeModel() {
// Must call this promise before the model hook otherwise
// the model doesn't hydrate from OpenAPI correctly.
return this.pathHelp.getNewModel('pki/certificate/generate', this.secretMountPath.currentPath);
}
async model() {
const { role } = this.paramsFor('roles/role');

View File

@ -11,13 +11,6 @@ withConfirmLeave();
export default class PkiRoleSignRoute extends Route {
@service store;
@service secretMountPath;
@service pathHelp;
beforeModel() {
// Must call this promise before the model hook otherwise
// the model doesn't hydrate from OpenAPI correctly.
return this.pathHelp.getNewModel('pki/certificate/sign', this.secretMountPath.currentPath);
}
model() {
const { role } = this.paramsFor('roles/role');

View File

@ -68,7 +68,7 @@
</EmptyState>
{{/if}}
{{else}}
<EmptyState @title="PKI not configured" @message={{this.message}}>
<EmptyState @title="PKI not configured" @message={{this.notConfiguredMessage}}>
<LinkTo @route="configuration.create">
Configure PKI
</LinkTo>

View File

@ -93,7 +93,7 @@
</LinkedBlock>
{{/each}}
{{else}}
<EmptyState @title="PKI not configured" @message={{this.message}}>
<EmptyState @title="PKI not configured" @message={{this.notConfiguredMessage}}>
<LinkTo @route="configuration.create">
Configure PKI
</LinkTo>

View File

@ -19,7 +19,7 @@
/>
{{else}}
<Toolbar />
<EmptyState @title="PKI not configured" @message={{this.message}}>
<EmptyState @title="PKI not configured" @message={{this.notConfiguredMessage}}>
<LinkTo @route="configuration.create">
Configure PKI
</LinkTo>

View File

@ -21,7 +21,7 @@
{{#if this.model.hasConfig}}
<Page::PkiOverview @issuers={{this.model.issuers}} @roles={{this.model.roles}} @engine={{this.model.engine}} />
{{else}}
<EmptyState @title="PKI not configured" @message={{this.message}}>
<EmptyState @title="PKI not configured" @message={{this.notConfiguredMessage}}>
<LinkTo @route="configuration.create">
Configure PKI
</LinkTo>

View File

@ -67,7 +67,7 @@
{{/if}}
{{else}}
<Toolbar />
<EmptyState @title="PKI not configured" @message={{this.message}}>
<EmptyState @title="PKI not configured" @message={{this.notConfiguredMessage}}>
<LinkTo @route="configuration.create">
Configure PKI
</LinkTo>