Hamid Ghaf e55c18ed12
adding copyright header (#19555)
* adding copyright header

* fix fmt and a test
2023-03-15 09:00:52 -07:00

46 lines
1.2 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* 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 { hash } from 'rsvp';
@withConfirmLeave('model.config', ['model.urls'])
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({
config: this.store.createRecord('pki/action'),
urls: this.getOrCreateUrls(this.secretMountPath.currentPath),
});
}
setupController(controller, resolvedModel) {
super.setupController(controller, resolvedModel);
controller.breadcrumbs = [
{ label: 'secrets', route: 'secrets', linkExternal: true },
{ label: this.secretMountPath.currentPath, route: 'overview' },
{ label: 'configure' },
];
}
async getOrCreateUrls(backend) {
try {
return this.store.findRecord('pki/urls', backend);
} catch (e) {
return this.store.createRecord('pki/urls', { id: backend });
}
}
}