2018-04-03 14:16:57 +00:00
|
|
|
import Ember from 'ember';
|
|
|
|
import DS from 'ember-data';
|
2018-06-12 21:06:37 +00:00
|
|
|
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;
|
2018-06-12 21:06:37 +00:00
|
|
|
const { computed } = Ember;
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-08-28 00:54:30 +00:00
|
|
|
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,
|
|
|
|
}),
|
2018-08-28 00:54:30 +00:00
|
|
|
// 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
|
|
|
}),
|
2018-08-28 00:54:30 +00:00
|
|
|
policyArns: attr({
|
|
|
|
editType: 'stringArray',
|
|
|
|
label: 'Policy ARNs',
|
2018-04-03 14:16:57 +00:00
|
|
|
}),
|
2018-08-28 00:54:30 +00:00
|
|
|
policyDocument: attr('string', {
|
|
|
|
editType: 'json',
|
|
|
|
}),
|
|
|
|
fields: computed('credentialType', function() {
|
|
|
|
let keys;
|
|
|
|
let credentialType = this.get('credentialType');
|
|
|
|
let keysForType = {
|
|
|
|
iam_user: ['name', 'credentialType', 'policyArns', 'policyDocument'],
|
|
|
|
assumed_role: ['name', 'credentialType', 'roleArns', 'policyDocument'],
|
|
|
|
federation_token: ['name', 'credentialType', 'policyDocument'],
|
|
|
|
};
|
|
|
|
keys = keysForType[credentialType];
|
2018-06-12 21:06:37 +00:00
|
|
|
return expandAttributeMeta(this, keys);
|
2018-04-03 14:16:57 +00:00
|
|
|
}),
|
|
|
|
|
2018-06-12 21:06:37 +00:00
|
|
|
updatePath: lazyCapabilities(apiPath`${'backend'}/roles/${'id'}`, 'backend', 'id'),
|
2018-04-03 14:16:57 +00:00
|
|
|
canDelete: computed.alias('updatePath.canDelete'),
|
|
|
|
canEdit: computed.alias('updatePath.canUpdate'),
|
|
|
|
canRead: computed.alias('updatePath.canRead'),
|
|
|
|
|
2018-06-12 21:06:37 +00:00
|
|
|
generatePath: lazyCapabilities(apiPath`${'backend'}/creds/${'id'}`, 'backend', 'id'),
|
2018-04-03 14:16:57 +00:00
|
|
|
canGenerate: computed.alias('generatePath.canUpdate'),
|
|
|
|
});
|