open-vault/ui/app/models/iam-credential.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-04-03 14:16:57 +00:00
import DS from 'ember-data';
import Ember from 'ember';
import { expandAttributeMeta } from 'vault/utils/field-to-attrs';
2018-04-03 14:16:57 +00:00
const { attr } = DS;
const { computed } = Ember;
2018-04-03 14:16:57 +00:00
const CREATE_FIELDS = ['ttl'];
const DISPLAY_FIELDS = ['accessKey', 'secretKey', 'securityToken', 'leaseId', 'renewable', 'leaseDuration'];
export default DS.Model.extend({
role: attr('object', {
readOnly: true,
}),
withSTS: attr('boolean', {
readOnly: true,
}),
ttl: attr({
editType: 'ttl',
defaultValue: '1h',
}),
leaseId: attr('string'),
renewable: attr('boolean'),
leaseDuration: attr('number'),
accessKey: attr('string'),
secretKey: attr('string'),
securityToken: attr('string'),
attrs: computed('accessKey', function() {
let keys = this.get('accessKey') ? DISPLAY_FIELDS.slice(0) : CREATE_FIELDS.slice(0);
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);
}),
});