mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-03 12:07:54 +00:00
VAULT-13220 use decorator instead of extending overview route (#19294)
This commit is contained in:
36
ui/lib/pki/addon/decorators/check-config.js
Normal file
36
ui/lib/pki/addon/decorators/check-config.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import Route from '@ember/routing/route';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the overview, roles, issuers, certificates, and key routes all need to be aware of the whether there is a config for the engine
|
||||||
|
* if the user has not configured they are prompted to do so in each of the routes
|
||||||
|
* decorate the necessary routes to perform the check in the beforeModel hook since that may change what is returned for the model
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function withConfig() {
|
||||||
|
return function decorator(SuperClass) {
|
||||||
|
if (!Object.prototype.isPrototypeOf.call(Route, SuperClass)) {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.error(
|
||||||
|
'withConfig decorator must be used on an instance of ember Route class. Decorator not applied to returned class'
|
||||||
|
);
|
||||||
|
return SuperClass;
|
||||||
|
}
|
||||||
|
return class CheckConfig extends SuperClass {
|
||||||
|
shouldPromptConfig = false;
|
||||||
|
|
||||||
|
async beforeModel() {
|
||||||
|
super.beforeModel(...arguments);
|
||||||
|
|
||||||
|
// When the engine is configured, it creates a default issuer.
|
||||||
|
// If the issuers list is empty, we know it hasn't been configured
|
||||||
|
return (
|
||||||
|
this.store
|
||||||
|
.query('pki/issuer', { backend: this.secretMountPath.currentPath })
|
||||||
|
.then(() => (this.shouldPromptConfig = true))
|
||||||
|
// this endpoint is unauthenticated, so we're not worried about permissions errors
|
||||||
|
.catch(() => (this.shouldPromptConfig = false))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
import PkiOverviewRoute from '../overview';
|
import Route from '@ember/routing/route';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
|
import { withConfig } from 'pki/decorators/check-config';
|
||||||
import { hash } from 'rsvp';
|
import { hash } from 'rsvp';
|
||||||
|
|
||||||
export default class PkiCertificatesIndexRoute extends PkiOverviewRoute {
|
@withConfig()
|
||||||
|
export default class PkiCertificatesIndexRoute extends Route {
|
||||||
@service store;
|
@service store;
|
||||||
@service secretMountPath;
|
@service secretMountPath;
|
||||||
|
|
||||||
@@ -20,7 +22,7 @@ export default class PkiCertificatesIndexRoute extends PkiOverviewRoute {
|
|||||||
|
|
||||||
model() {
|
model() {
|
||||||
return hash({
|
return hash({
|
||||||
hasConfig: this.hasConfig(),
|
hasConfig: this.shouldPromptConfig,
|
||||||
certificates: this.fetchCertificates(),
|
certificates: this.fetchCertificates(),
|
||||||
parentModel: this.modelFor('certificates'),
|
parentModel: this.modelFor('certificates'),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import PkiOverviewRoute from '../overview';
|
import Route from '@ember/routing/route';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
|
|
||||||
export default class PkiIssuersListRoute extends PkiOverviewRoute {
|
export default class PkiIssuersListRoute extends Route {
|
||||||
@service store;
|
@service store;
|
||||||
@service secretMountPath;
|
@service secretMountPath;
|
||||||
@service pathHelp;
|
@service pathHelp;
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import PkiOverviewRoute from '../overview';
|
import Route from '@ember/routing/route';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
|
import { withConfig } from 'pki/decorators/check-config';
|
||||||
import { hash } from 'rsvp';
|
import { hash } from 'rsvp';
|
||||||
export default class PkiKeysIndexRoute extends PkiOverviewRoute {
|
|
||||||
|
@withConfig()
|
||||||
|
export default class PkiKeysIndexRoute extends Route {
|
||||||
@service store;
|
@service store;
|
||||||
@service secretMountPath;
|
@service secretMountPath;
|
||||||
@service pathHelp;
|
@service pathHelp;
|
||||||
@@ -13,7 +16,7 @@ export default class PkiKeysIndexRoute extends PkiOverviewRoute {
|
|||||||
|
|
||||||
model() {
|
model() {
|
||||||
return hash({
|
return hash({
|
||||||
hasConfig: this.hasConfig(),
|
hasConfig: this.shouldPromptConfig,
|
||||||
parentModel: this.modelFor('keys'),
|
parentModel: this.modelFor('keys'),
|
||||||
keyModels: this.store.query('pki/key', { backend: this.secretMountPath.currentPath }).catch((err) => {
|
keyModels: this.store.query('pki/key', { backend: this.secretMountPath.currentPath }).catch((err) => {
|
||||||
if (err.httpStatus === 404) {
|
if (err.httpStatus === 404) {
|
||||||
|
|||||||
@@ -1,24 +1,14 @@
|
|||||||
import Route from '@ember/routing/route';
|
import Route from '@ember/routing/route';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
|
import { withConfig } from 'pki/decorators/check-config';
|
||||||
import { hash } from 'rsvp';
|
import { hash } from 'rsvp';
|
||||||
|
|
||||||
|
@withConfig()
|
||||||
export default class PkiOverviewRoute extends Route {
|
export default class PkiOverviewRoute extends Route {
|
||||||
@service secretMountPath;
|
@service secretMountPath;
|
||||||
@service auth;
|
@service auth;
|
||||||
@service store;
|
@service store;
|
||||||
|
|
||||||
hasConfig() {
|
|
||||||
// When the engine is configured, it creates a default issuer.
|
|
||||||
// If the issuers list is empty, we know it hasn't been configured
|
|
||||||
return (
|
|
||||||
this.store
|
|
||||||
.query('pki/issuer', { backend: this.secretMountPath.currentPath })
|
|
||||||
.then(() => true)
|
|
||||||
// this endpoint is unauthenticated, so we're not worried about permissions errors
|
|
||||||
.catch(() => false)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetchAllRoles() {
|
async fetchAllRoles() {
|
||||||
try {
|
try {
|
||||||
return await this.store.query('pki/role', { backend: this.secretMountPath.currentPath });
|
return await this.store.query('pki/role', { backend: this.secretMountPath.currentPath });
|
||||||
@@ -37,7 +27,7 @@ export default class PkiOverviewRoute extends Route {
|
|||||||
|
|
||||||
async model() {
|
async model() {
|
||||||
return hash({
|
return hash({
|
||||||
hasConfig: this.hasConfig(),
|
hasConfig: this.shouldPromptConfig,
|
||||||
engine: this.modelFor('application'),
|
engine: this.modelFor('application'),
|
||||||
roles: this.fetchAllRoles(),
|
roles: this.fetchAllRoles(),
|
||||||
issuers: this.fetchAllIssuers(),
|
issuers: this.fetchAllIssuers(),
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import PkiOverviewRoute from '../overview';
|
import Route from '@ember/routing/route';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
|
import { withConfig } from 'pki/decorators/check-config';
|
||||||
import { hash } from 'rsvp';
|
import { hash } from 'rsvp';
|
||||||
|
|
||||||
export default class PkiRolesIndexRoute extends PkiOverviewRoute {
|
@withConfig()
|
||||||
|
export default class PkiRolesIndexRoute extends Route {
|
||||||
@service store;
|
@service store;
|
||||||
@service secretMountPath;
|
@service secretMountPath;
|
||||||
|
|
||||||
@@ -20,7 +22,7 @@ export default class PkiRolesIndexRoute extends PkiOverviewRoute {
|
|||||||
|
|
||||||
model() {
|
model() {
|
||||||
return hash({
|
return hash({
|
||||||
hasConfig: this.hasConfig(),
|
hasConfig: this.shouldPromptConfig,
|
||||||
roles: this.fetchRoles(),
|
roles: this.fetchRoles(),
|
||||||
parentModel: this.modelFor('roles'),
|
parentModel: this.modelFor('roles'),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user