open-vault/ui/app/routes/vault/cluster/secrets/backend/create.js

60 lines
1.8 KiB
JavaScript
Raw Normal View History

import { hash } from 'rsvp';
import { inject as service } from '@ember/service';
import EmberObject from '@ember/object';
2018-04-03 14:16:57 +00:00
import EditBase from './secret-edit';
import KeyMixin from 'vault/models/key-mixin';
var SecretProxy = EmberObject.extend(KeyMixin, {
2018-04-03 14:16:57 +00:00
store: null,
toModel() {
return this.getProperties('id', 'secretData', 'backend');
},
createRecord(backend) {
let backendModel = this.store.peekRecord('secret-engine', backend);
return this.store.createRecord(backendModel.get('modelTypeForKV'), this.toModel());
2018-04-03 14:16:57 +00:00
},
willDestroy() {
this.store = null;
},
2018-04-03 14:16:57 +00:00
});
export default EditBase.extend({
wizard: service(),
2018-04-03 14:16:57 +00:00
createModel(transition, parentKey) {
const { backend } = this.paramsFor('vault.cluster.secrets.backend');
const modelType = this.modelType(backend);
if (modelType === 'role-ssh') {
return this.store.createRecord(modelType, { keyType: 'ca' });
}
if (modelType !== 'secret' && modelType !== 'secret-v2') {
2018-08-28 05:03:55 +00:00
if (this.get('wizard.featureState') === 'details' && this.get('wizard.componentState') === 'transit') {
this.get('wizard').transitionFeatureMachine('details', 'CONTINUE', 'transit');
}
2018-04-03 14:16:57 +00:00
return this.store.createRecord(modelType);
}
const key = transition.queryParams.initialKey || '';
const model = SecretProxy.create({
initialParentKey: parentKey,
store: this.store,
});
if (key) {
// have to set this after so that it will be
// computed properly in the template (it's dependent on `initialParentKey`)
model.set('keyWithoutParent', key);
}
return model;
},
model(params, transition) {
const parentKey = params.secret ? params.secret : '';
return hash({
2018-04-03 14:16:57 +00:00
secret: this.createModel(transition, parentKey),
capabilities: {},
2018-04-03 14:16:57 +00:00
});
},
});