2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2020-07-14 18:47:35 -04:00
|
|
|
import GeneratedScopeModel from '../generated/models/scope';
|
2020-07-15 09:43:30 -04:00
|
|
|
import { computed } from '@ember/object';
|
|
|
|
|
|
|
|
|
|
export const scopeTypes = {
|
|
|
|
|
global: 'global',
|
|
|
|
|
org: 'org',
|
2020-09-16 14:29:02 -04:00
|
|
|
project: 'project',
|
2020-07-15 09:43:30 -04:00
|
|
|
};
|
2020-07-14 18:47:35 -04:00
|
|
|
|
|
|
|
|
export default class ScopeModel extends GeneratedScopeModel {
|
2020-07-15 12:41:58 -04:00
|
|
|
// =attributes
|
2020-07-15 09:43:30 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
@computed('type')
|
|
|
|
|
get isGlobal() {
|
|
|
|
|
return this.type === scopeTypes.global;
|
|
|
|
|
}
|
|
|
|
|
// There is only one global scope and it cannot be created by clients,
|
|
|
|
|
// thus no set.
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
@computed('type')
|
|
|
|
|
get isOrg() {
|
|
|
|
|
return this.type === scopeTypes.org;
|
|
|
|
|
}
|
|
|
|
|
set isOrg(value) {
|
|
|
|
|
if (value) this.type = scopeTypes.org;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
@computed('type')
|
|
|
|
|
get isProject() {
|
|
|
|
|
return this.type === scopeTypes.project;
|
|
|
|
|
}
|
|
|
|
|
set isProject(value) {
|
|
|
|
|
if (value) this.type = scopeTypes.project;
|
|
|
|
|
}
|
2024-01-12 11:29:19 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Attach policy via the `attach-staorage-policy` method.
|
|
|
|
|
* @param {[string]} policyId
|
|
|
|
|
* @param {object} options
|
|
|
|
|
* @param {object} options.adapterOptions
|
|
|
|
|
* @return {Promise}
|
|
|
|
|
*/
|
|
|
|
|
attachStoragePolicy(policyId, options = { adapterOptions: {} }) {
|
|
|
|
|
const defaultAdapterOptions = {
|
|
|
|
|
method: 'attach-storage-policy',
|
|
|
|
|
policyId,
|
|
|
|
|
};
|
|
|
|
|
// There is no "deep merge" in ES.
|
|
|
|
|
return this.save({
|
|
|
|
|
...options,
|
|
|
|
|
adapterOptions: {
|
|
|
|
|
...defaultAdapterOptions,
|
|
|
|
|
...options.adapterOptions,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detaches policy via the `detach-storage-policy` method.
|
|
|
|
|
* @param {[string]} policyId
|
|
|
|
|
* @param {object} options
|
|
|
|
|
* @param {object} options.adapterOptions
|
|
|
|
|
* @return {Promise}
|
|
|
|
|
*/
|
|
|
|
|
detachStoragePolicy(policyId, options = { adapterOptions: {} }) {
|
|
|
|
|
const defaultAdapterOptions = {
|
|
|
|
|
method: 'detach-storage-policy',
|
|
|
|
|
policyId,
|
|
|
|
|
};
|
|
|
|
|
// There is no "deep merge" in ES.
|
|
|
|
|
return this.save({
|
|
|
|
|
...options,
|
|
|
|
|
adapterOptions: {
|
|
|
|
|
...defaultAdapterOptions,
|
|
|
|
|
...options.adapterOptions,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-07-14 18:47:35 -04:00
|
|
|
}
|