2019-06-21 21:05:45 +00:00
|
|
|
import DS from 'ember-data';
|
|
|
|
import { computed } from '@ember/object';
|
2019-06-25 20:57:50 +00:00
|
|
|
import { expandAttributeMeta } from 'vault/utils/field-to-attrs';
|
|
|
|
import fieldToAttrs from 'vault/utils/field-to-attrs';
|
2019-06-28 21:07:45 +00:00
|
|
|
import apiPath from 'vault/utils/api-path';
|
|
|
|
import attachCapabilities from 'vault/lib/attach-capabilities';
|
2019-06-21 21:05:45 +00:00
|
|
|
|
|
|
|
const { attr } = DS;
|
2019-07-02 21:23:07 +00:00
|
|
|
export const COMPUTEDS = {
|
|
|
|
operationFields: computed('newFields', function() {
|
|
|
|
return this.newFields.filter(key => key.startsWith('operation'));
|
|
|
|
}),
|
|
|
|
|
|
|
|
operationFieldsWithoutSpecial: computed('operationFields', function() {
|
|
|
|
return this.operationFields.slice().removeObjects(['operationAll', 'operationNone']);
|
|
|
|
}),
|
|
|
|
|
2019-07-23 21:00:00 +00:00
|
|
|
tlsFields: computed(function() {
|
|
|
|
return ['tlsClientKeyBits', 'tlsClientKeyType', 'tlsClientTtl'];
|
|
|
|
}),
|
|
|
|
|
|
|
|
nonOperationFields: computed('tlsFields', 'operationFields', function() {
|
|
|
|
let excludeFields = ['role'].concat(this.operationFields, this.tlsFields);
|
2019-07-02 21:23:07 +00:00
|
|
|
return this.newFields.slice().removeObjects(excludeFields);
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
const Model = DS.Model.extend(COMPUTEDS, {
|
2019-06-21 21:05:45 +00:00
|
|
|
useOpenAPI: true,
|
|
|
|
backend: attr({ readOnly: true }),
|
|
|
|
scope: attr({ readOnly: true }),
|
2019-07-02 21:23:07 +00:00
|
|
|
name: attr({ readOnly: true }),
|
2019-06-21 21:05:45 +00:00
|
|
|
getHelpUrl(path) {
|
|
|
|
return `/v1/${path}/scope/example/role/example?help=1`;
|
|
|
|
},
|
2019-07-23 21:00:00 +00:00
|
|
|
fieldGroups: computed('fields', 'tlsFields', 'nonOperationFields', function() {
|
|
|
|
const groups = [{ TLS: this.tlsFields }];
|
|
|
|
if (this.nonOperationFields.length) {
|
|
|
|
groups.unshift({ default: this.nonOperationFields });
|
|
|
|
}
|
2019-07-02 21:23:07 +00:00
|
|
|
let ret = fieldToAttrs(this, groups);
|
|
|
|
return ret;
|
2019-06-21 21:05:45 +00:00
|
|
|
}),
|
2019-06-25 20:57:50 +00:00
|
|
|
|
2019-07-02 21:23:07 +00:00
|
|
|
operationFormFields: computed('operationFieldsWithoutSpecial', function() {
|
2019-07-23 21:00:00 +00:00
|
|
|
let objects = [
|
|
|
|
'operationCreate',
|
|
|
|
'operationActivate',
|
|
|
|
'operationGet',
|
|
|
|
'operationLocate',
|
|
|
|
'operationRekey',
|
|
|
|
'operationRevoke',
|
|
|
|
'operationDestroy',
|
|
|
|
];
|
|
|
|
|
|
|
|
let attributes = ['operationAddAttribute', 'operationGetAttributes'];
|
|
|
|
let server = ['operationDiscoverVersion'];
|
|
|
|
let others = this.operationFieldsWithoutSpecial.slice().removeObjects(objects.concat(attributes, server));
|
|
|
|
const groups = [
|
|
|
|
{ 'Managed Cryptographic Objects': objects },
|
|
|
|
{ 'Object Attributes': attributes },
|
|
|
|
{ Server: server },
|
|
|
|
];
|
|
|
|
if (others.length) {
|
|
|
|
groups.push({
|
|
|
|
'': others,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return fieldToAttrs(this, groups);
|
|
|
|
}),
|
|
|
|
tlsFormFields: computed('tlsFields', function() {
|
|
|
|
return expandAttributeMeta(this, this.tlsFields);
|
2019-07-02 21:23:07 +00:00
|
|
|
}),
|
|
|
|
fields: computed('nonOperationFields', function() {
|
|
|
|
return expandAttributeMeta(this, this.nonOperationFields);
|
2019-06-25 20:57:50 +00:00
|
|
|
}),
|
2019-06-21 21:05:45 +00:00
|
|
|
});
|
2019-06-28 21:07:45 +00:00
|
|
|
|
|
|
|
export default attachCapabilities(Model, {
|
|
|
|
updatePath: apiPath`${'backend'}/scope/${'scope'}/role/${'id'}`,
|
|
|
|
});
|