2018-09-25 16:28:26 +00:00
|
|
|
import { alias } from '@ember/object/computed';
|
|
|
|
import { computed } from '@ember/object';
|
2018-04-03 14:16:57 +00:00
|
|
|
import DS from 'ember-data';
|
2018-06-12 21:06:37 +00:00
|
|
|
import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
let { attr } = DS;
|
|
|
|
|
|
|
|
export default DS.Model.extend({
|
|
|
|
name: attr('string'),
|
|
|
|
policy: attr('string'),
|
|
|
|
policyType: computed(function() {
|
|
|
|
return this.constructor.modelName.split('/')[1];
|
|
|
|
}),
|
|
|
|
|
2018-06-12 21:06:37 +00:00
|
|
|
updatePath: lazyCapabilities(apiPath`sys/policies/${'policyType'}/${'id'}`, 'id', 'policyType'),
|
2018-09-25 16:28:26 +00:00
|
|
|
canDelete: alias('updatePath.canDelete'),
|
|
|
|
canEdit: alias('updatePath.canUpdate'),
|
|
|
|
canRead: alias('updatePath.canRead'),
|
2018-04-03 14:16:57 +00:00
|
|
|
format: computed('policy', function() {
|
|
|
|
let policy = this.get('policy');
|
|
|
|
let isJSON;
|
|
|
|
try {
|
|
|
|
let parsed = JSON.parse(policy);
|
|
|
|
if (parsed) {
|
|
|
|
isJSON = true;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// can't parse JSON
|
|
|
|
isJSON = false;
|
|
|
|
}
|
|
|
|
return isJSON ? 'json' : 'hcl';
|
|
|
|
}),
|
|
|
|
});
|