2018-04-03 14:16:57 +00:00
|
|
|
import DS from 'ember-data';
|
|
|
|
import Ember from 'ember';
|
2018-06-12 21:06:37 +00:00
|
|
|
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-08-28 00:54:30 +00:00
|
|
|
const CREATE_FIELDS = ['ttl', 'roleArn'];
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
const DISPLAY_FIELDS = ['accessKey', 'secretKey', 'securityToken', 'leaseId', 'renewable', 'leaseDuration'];
|
|
|
|
export default DS.Model.extend({
|
2018-08-28 00:54:30 +00:00
|
|
|
helpText:
|
|
|
|
'For Vault roles that have a credential type of iam_user, these attributes are optional and you may simply submit the form.',
|
2018-04-03 14:16:57 +00:00
|
|
|
role: attr('object', {
|
|
|
|
readOnly: true,
|
|
|
|
}),
|
|
|
|
|
2018-08-28 00:54:30 +00:00
|
|
|
roleArn: attr('string', {
|
|
|
|
label: 'Role ARN',
|
|
|
|
helpText:
|
|
|
|
'The ARN of the role to assume if credential_type on the Vault role is assumed_role. Optional if the role has a single role ARN; required otherwise.',
|
2018-04-03 14:16:57 +00:00
|
|
|
}),
|
|
|
|
ttl: attr({
|
|
|
|
editType: 'ttl',
|
2018-08-28 04:30:17 +00:00
|
|
|
defaultValue: '3600s',
|
2018-08-28 00:54:30 +00:00
|
|
|
label: 'TTL',
|
|
|
|
helpText:
|
|
|
|
'Specifies the TTL for the use of the STS token. Valid only when credential_type is assumed_role or federation_token.',
|
2018-04-03 14:16:57 +00:00
|
|
|
}),
|
|
|
|
leaseId: attr('string'),
|
|
|
|
renewable: attr('boolean'),
|
|
|
|
leaseDuration: attr('number'),
|
|
|
|
accessKey: attr('string'),
|
|
|
|
secretKey: attr('string'),
|
|
|
|
securityToken: attr('string'),
|
|
|
|
|
2018-08-28 00:54:30 +00:00
|
|
|
attrs: computed('accessKey', 'securityToken', function() {
|
|
|
|
let keys =
|
|
|
|
this.get('accessKey') || this.get('securityToken') ? DISPLAY_FIELDS.slice(0) : CREATE_FIELDS.slice(0);
|
2018-06-12 21:06:37 +00:00
|
|
|
return expandAttributeMeta(this, keys);
|
2018-04-03 14:16:57 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
toCreds: computed('accessKey', 'secretKey', 'securityToken', 'leaseId', function() {
|
|
|
|
const props = this.getProperties('accessKey', 'secretKey', 'securityToken', 'leaseId');
|
|
|
|
const propsWithVals = Object.keys(props).reduce((ret, prop) => {
|
|
|
|
if (props[prop]) {
|
|
|
|
ret[prop] = props[prop];
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}, {});
|
|
|
|
return JSON.stringify(propsWithVals, null, 2);
|
|
|
|
}),
|
|
|
|
});
|