2018-09-25 16:28:26 +00:00
|
|
|
import { isBlank } from '@ember/utils';
|
|
|
|
import { set, get } from '@ember/object';
|
2018-04-03 14:16:57 +00:00
|
|
|
import RoleEdit from './role-edit';
|
|
|
|
const SHOW_ROUTE = 'vault.cluster.secrets.backend.show';
|
|
|
|
|
|
|
|
export default RoleEdit.extend({
|
|
|
|
actions: {
|
|
|
|
createOrUpdate(type, event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
const modelId = this.get('model.id');
|
|
|
|
// prevent from submitting if there's no key
|
|
|
|
// maybe do something fancier later
|
2018-09-25 16:28:26 +00:00
|
|
|
if (type === 'create' && isBlank(modelId)) {
|
2018-04-03 14:16:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-08-28 00:54:30 +00:00
|
|
|
|
|
|
|
var credential_type = get(this, 'model.credential_type');
|
2018-08-28 05:03:55 +00:00
|
|
|
if (credential_type == 'iam_user') {
|
2018-08-28 00:54:30 +00:00
|
|
|
set(this, 'model.role_arns', []);
|
|
|
|
}
|
2018-08-28 05:03:55 +00:00
|
|
|
if (credential_type == 'assumed_role') {
|
2018-08-28 00:54:30 +00:00
|
|
|
set(this, 'model.policy_arns', []);
|
|
|
|
}
|
2018-08-28 05:03:55 +00:00
|
|
|
if (credential_type == 'federation_token') {
|
2018-08-28 00:54:30 +00:00
|
|
|
set(this, 'model.role_arns', []);
|
|
|
|
set(this, 'model.policy_arns', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
var policy_document = get(this, 'model.policy_document');
|
|
|
|
if (policy_document == '{}') {
|
|
|
|
set(this, 'model.policy_document', '');
|
2018-04-03 14:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.persist('save', () => {
|
|
|
|
this.hasDataChanges();
|
|
|
|
this.transitionToRoute(SHOW_ROUTE, modelId);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
codemirrorUpdated(attr, val, codemirror) {
|
|
|
|
codemirror.performLint();
|
|
|
|
const hasErrors = codemirror.state.lint.marked.length > 0;
|
|
|
|
|
|
|
|
if (!hasErrors) {
|
|
|
|
set(this.get('model'), attr, val);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|