move secret creation to always be at the root level, and simplify model creation so we're always directly manipulating a model

This commit is contained in:
Matthew Irish 2018-10-05 22:04:48 -05:00
parent b74ed60497
commit 46773189d5
3 changed files with 53 additions and 58 deletions

View File

@ -1 +1,45 @@
export { default } from './create';
import { hash } from 'rsvp';
import { inject as service } from '@ember/service';
import EditBase from './secret-edit';
let secretModel = (store, backend, key) => {
let backendModel = store.peekRecord('secret-engine', backend);
let modelType = backendModel.get('modelTypeForKV');
if (modelType !== 'secret-v2') {
return store.createRecord(modelType, {
id: key,
});
}
let secret = store.createRecord(modelType);
secret.set('engine', backendModel);
let version = store.createRecord('secret-v2-version', {
path: key,
});
secret.set('selectedVersion', version);
return secret;
};
export default EditBase.extend({
wizard: service(),
createModel(transition) {
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') {
if (this.get('wizard.featureState') === 'details' && this.get('wizard.componentState') === 'transit') {
this.get('wizard').transitionFeatureMachine('details', 'CONTINUE', 'transit');
}
return this.store.createRecord(modelType);
}
return secretModel(this.store, backend, transition.queryParams.initialKey);
},
model(params, transition) {
return hash({
secret: this.createModel(transition),
capabilities: {},
});
},
});

View File

@ -1,59 +1,10 @@
import { hash } from 'rsvp';
import { inject as service } from '@ember/service';
import EmberObject from '@ember/object';
import EditBase from './secret-edit';
import KeyMixin from 'vault/models/key-mixin';
import Route from '@ember/routing/route';
var SecretProxy = EmberObject.extend(KeyMixin, {
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());
},
willDestroy() {
this.store = null;
},
});
export default EditBase.extend({
wizard: service(),
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') {
if (this.get('wizard.featureState') === 'details' && this.get('wizard.componentState') === 'transit') {
this.get('wizard').transitionFeatureMachine('details', 'CONTINUE', 'transit');
}
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({
secret: this.createModel(transition, parentKey),
capabilities: {},
export default Route.extend({
beforeModel(transition) {
let { secret } = this.paramsFor(this.routeName);
return this.transitionTo('vault.cluster.secrets.backend.create-root', {
queryParams: { initialKey: secret },
});
},
});

View File

@ -32,8 +32,8 @@
<div class="control">
{{#secret-link
mode="create"
secret=(or baseKey.id '')
queryParams=(query-params initialKey='')
secret=''
queryParams=(query-params initialKey=baseKey.id)
class="button has-icon-right is-ghost is-compact"
data-test-secret-create=true
}}