open-vault/ui/app/models/role-aws.js

73 lines
2 KiB
JavaScript
Raw Normal View History

import { alias } from '@ember/object/computed';
import { computed } from '@ember/object';
2018-04-03 14:16:57 +00:00
import DS from 'ember-data';
import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities';
import { expandAttributeMeta } from 'vault/utils/field-to-attrs';
2018-04-03 14:16:57 +00:00
const { attr } = DS;
const CREDENTIAL_TYPES = [
{
value: 'iam_user',
displayName: 'IAM User',
},
{
value: 'assumed_role',
displayName: 'Assumed Role',
},
{
value: 'federation_token',
displayName: 'Federation Token',
},
];
2018-04-03 14:16:57 +00:00
export default DS.Model.extend({
backend: attr('string', {
readOnly: true,
}),
name: attr('string', {
label: 'Role name',
fieldValue: 'id',
readOnly: true,
}),
2019-02-14 18:52:34 +00:00
useOpenAPI: false,
// credentialTypes are for backwards compatibility.
// we use this to populate "credentialType" in
// the serializer. if there is more than one, the
// show and edit pages will show a warning
credentialTypes: attr('array', {
readOnly: true,
}),
credentialType: attr('string', {
defaultValue: 'iam_user',
possibleValues: CREDENTIAL_TYPES,
}),
roleArns: attr({
editType: 'stringArray',
label: 'Role ARNs',
2018-04-03 14:16:57 +00:00
}),
policyArns: attr({
editType: 'stringArray',
label: 'Policy ARNs',
2018-04-03 14:16:57 +00:00
}),
policyDocument: attr('string', {
editType: 'json',
}),
fields: computed('credentialType', function() {
2019-02-14 18:52:34 +00:00
let credentialType = this.credentialType;
let keysForType = {
iam_user: ['name', 'credentialType', 'policyArns', 'policyDocument'],
assumed_role: ['name', 'credentialType', 'roleArns', 'policyDocument'],
federation_token: ['name', 'credentialType', 'policyDocument'],
};
2018-04-03 14:16:57 +00:00
2019-02-14 18:52:34 +00:00
return expandAttributeMeta(this, keysForType[credentialType]);
}),
updatePath: lazyCapabilities(apiPath`${'backend'}/roles/${'id'}`, 'backend', 'id'),
canDelete: alias('updatePath.canDelete'),
canEdit: alias('updatePath.canUpdate'),
canRead: alias('updatePath.canRead'),
2018-04-03 14:16:57 +00:00
generatePath: lazyCapabilities(apiPath`${'backend'}/creds/${'id'}`, 'backend', 'id'),
canGenerate: alias('generatePath.canUpdate'),
2018-04-03 14:16:57 +00:00
});