vault/ui/lib/pki/addon/routes/application.js
Chelsea Shaw da7fad68b8
UI: Replace getNewModel with hydrateModel when model exists (#27978)
* Replace getNewModel with hydrateModel when model exists

* Update getNewModel to only handle nonexistant model types

* Update test

* clarify test

* Fix auth-config models which need hydration not generation

* rename file to match service name

* cleanup + tests

* Add comment about helpUrl method
2024-08-07 16:07:25 +00:00

32 lines
1.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Route from '@ember/routing/route';
import { service } from '@ember/service';
import { hash } from 'rsvp';
export default class PkiRoute extends Route {
@service pathHelp;
@service secretMountPath;
beforeModel() {
// 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({
acme: this.pathHelp.hydrateModel('pki/config/acme', mountPath),
certGenerate: this.pathHelp.hydrateModel('pki/certificate/generate', mountPath),
certSign: this.pathHelp.hydrateModel('pki/certificate/sign', mountPath),
cluster: this.pathHelp.hydrateModel('pki/config/cluster', mountPath),
key: this.pathHelp.hydrateModel('pki/key', mountPath),
role: this.pathHelp.hydrateModel('pki/role', mountPath),
signCsr: this.pathHelp.hydrateModel('pki/sign-intermediate', mountPath),
tidy: this.pathHelp.hydrateModel('pki/tidy', mountPath),
urls: this.pathHelp.hydrateModel('pki/config/urls', mountPath),
});
}
}