2018-04-03 14:16:57 +00:00
|
|
|
import Ember from 'ember';
|
|
|
|
import DS from 'ember-data';
|
|
|
|
|
|
|
|
const CONFIGURABLE_BACKEND_TYPES = ['aws', 'ssh', 'pki'];
|
|
|
|
|
|
|
|
export default Ember.Route.extend({
|
|
|
|
model() {
|
|
|
|
const { backend } = this.paramsFor(this.routeName);
|
2018-04-24 21:30:44 +00:00
|
|
|
return this.store.query('secret-engine', { path: backend }).then(modelList => {
|
|
|
|
let model = modelList && modelList.get('firstObject');
|
2018-04-03 14:16:57 +00:00
|
|
|
if (!model || !CONFIGURABLE_BACKEND_TYPES.includes(model.get('type'))) {
|
|
|
|
const error = new DS.AdapterError();
|
|
|
|
Ember.set(error, 'httpStatus', 404);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
return this.store.findRecord('secret-engine', backend).then(
|
|
|
|
() => {
|
|
|
|
return model;
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
afterModel(model, transition) {
|
|
|
|
const type = model.get('type');
|
|
|
|
if (type === 'pki') {
|
|
|
|
if (transition.targetName === this.routeName) {
|
|
|
|
return this.transitionTo(`${this.routeName}.section`, 'cert');
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type === 'aws') {
|
|
|
|
return this.store
|
|
|
|
.queryRecord('secret-engine', {
|
|
|
|
backend: model.id,
|
|
|
|
type,
|
|
|
|
})
|
|
|
|
.then(() => model, () => model);
|
|
|
|
}
|
|
|
|
return model;
|
|
|
|
},
|
|
|
|
|
|
|
|
setupController(controller, model) {
|
|
|
|
if (model.get('publicKey')) {
|
|
|
|
controller.set('configured', true);
|
|
|
|
}
|
|
|
|
return this._super(...arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
resetController(controller, isExiting) {
|
|
|
|
if (isExiting) {
|
|
|
|
controller.reset();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
refreshRoute() {
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|