2018-10-04 04:32:55 +00:00
|
|
|
|
import DS from 'ember-data';
|
2018-10-15 14:38:05 +00:00
|
|
|
|
import { computed } from '@ember/object';
|
2018-10-18 04:06:52 +00:00
|
|
|
|
import { alias } from '@ember/object/computed';
|
2018-10-15 14:38:05 +00:00
|
|
|
|
import { expandAttributeMeta } from 'vault/utils/field-to-attrs';
|
2018-10-17 03:10:41 +00:00
|
|
|
|
import KeyMixin from 'vault/mixins/key-mixin';
|
2018-10-18 04:06:52 +00:00
|
|
|
|
import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
2018-10-04 04:32:55 +00:00
|
|
|
|
const { attr, hasMany, belongsTo, Model } = DS;
|
|
|
|
|
|
2018-10-17 03:10:41 +00:00
|
|
|
|
export default Model.extend(KeyMixin, {
|
2018-10-18 04:06:52 +00:00
|
|
|
|
engine: belongsTo('secret-engine', { async: false }),
|
|
|
|
|
engineId: attr('string'),
|
2018-10-06 03:02:23 +00:00
|
|
|
|
versions: hasMany('secret-v2-version', { async: false, inverse: null }),
|
2018-10-10 04:44:08 +00:00
|
|
|
|
selectedVersion: belongsTo('secret-v2-version', { async: false, inverse: 'secret' }),
|
2018-10-04 04:32:55 +00:00
|
|
|
|
createdTime: attr(),
|
|
|
|
|
updatedTime: attr(),
|
|
|
|
|
currentVersion: attr('number'),
|
|
|
|
|
oldestVersion: attr('number'),
|
2018-10-15 14:38:05 +00:00
|
|
|
|
maxVersions: attr('number', {
|
|
|
|
|
defaultValue: 10,
|
|
|
|
|
label: 'Maximum Number of Versions',
|
|
|
|
|
}),
|
|
|
|
|
casRequired: attr('boolean', {
|
|
|
|
|
defaultValue: false,
|
|
|
|
|
label: 'Require Check and Set',
|
|
|
|
|
helpText:
|
|
|
|
|
'Writes will only be allowed if the key’s current version matches the version specified in the cas parameter',
|
|
|
|
|
}),
|
|
|
|
|
fields: computed(function() {
|
|
|
|
|
return expandAttributeMeta(this, ['maxVersions', 'casRequired']);
|
|
|
|
|
}),
|
2018-10-18 04:06:52 +00:00
|
|
|
|
versionPath: lazyCapabilities(apiPath`${'engineId'}/data/${'id'}`, 'engineId', 'id'),
|
|
|
|
|
secretPath: lazyCapabilities(apiPath`${'engineId'}/metadata/${'id'}`, 'engineId', 'id'),
|
|
|
|
|
|
|
|
|
|
canEdit: alias('versionPath.canUpdate'),
|
2018-12-03 14:22:13 +00:00
|
|
|
|
canDelete: alias('secretPath.canDelete'),
|
2018-10-18 04:06:52 +00:00
|
|
|
|
canRead: alias('secretPath.canRead'),
|
2018-10-04 04:32:55 +00:00
|
|
|
|
});
|