feat: 🎸 Add storage bucket models (#85)
* feat: 🎸 Add storage bucket models ✅ Closes: ICU-8076
This commit is contained in:
1 parent
c30bc3a554
commit
4d62e67f2a
4 files changed
+226
No files matched your search
@@ -0,0 +1,88 @@
|
||||
import BaseModel from '../../models/base';
|
||||
import { attr } from '@ember-data/model';
|
||||
|
||||
/**
|
||||
* A storage bucket is a resource that that represents a bucket in an external object store.
|
||||
*/
|
||||
export default class GeneratedStorageBucketModel extends BaseModel {
|
||||
// =attributes
|
||||
|
||||
@attr('string', {
|
||||
description: 'The type of the resource, to help differentiate schemas',
|
||||
})
|
||||
type;
|
||||
|
||||
@attr({
|
||||
description: 'Plugin information for this resource.',
|
||||
readOnly: true,
|
||||
})
|
||||
plugin;
|
||||
|
||||
@attr('string', {
|
||||
description: 'Optional name for identification purposes.',
|
||||
})
|
||||
name;
|
||||
|
||||
@attr('string', {
|
||||
description: 'Optional user-set description for identification purposes.',
|
||||
})
|
||||
description;
|
||||
|
||||
@attr('date', {
|
||||
description: 'The time this resource was created\nOutput only.',
|
||||
readOnly: true,
|
||||
})
|
||||
created_time;
|
||||
|
||||
@attr('date', {
|
||||
description: 'The time this resource was last updated\nOutput only.',
|
||||
readOnly: true,
|
||||
})
|
||||
updated_time;
|
||||
|
||||
@attr('number', {
|
||||
description: 'Current version number of this resource.',
|
||||
})
|
||||
version;
|
||||
|
||||
@attr('string', {
|
||||
description: 'The name of the bucket in the external object store.',
|
||||
})
|
||||
bucket_name;
|
||||
|
||||
@attr('string', {
|
||||
description:
|
||||
'The base path where session recordings will be stored in the external object store.',
|
||||
})
|
||||
bucket_prefix;
|
||||
|
||||
@attr('string', {
|
||||
description:
|
||||
'An expression used to filter the workers that have network access to a service that is hosting the external object store.',
|
||||
})
|
||||
worker_filter;
|
||||
|
||||
@attr('string', {
|
||||
isNestedAttribute: true,
|
||||
description: 'The AWS region to use.',
|
||||
})
|
||||
region;
|
||||
|
||||
@attr('string', {
|
||||
readOnly: true,
|
||||
isNestedAttribute: true,
|
||||
})
|
||||
client_secret_hmac;
|
||||
|
||||
@attr('string', {
|
||||
isNestedSecret: true,
|
||||
description: 'The AWS access key ID to use.',
|
||||
})
|
||||
access_key_id;
|
||||
|
||||
@attr('string', {
|
||||
isNestedSecret: true,
|
||||
description: 'The secret access key to use.',
|
||||
})
|
||||
secret_access_key;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import GeneratedStorageBucketModel from '../generated/models/storage-bucket';
|
||||
|
||||
export const TYPE_STORAGE_BUCKET_PLUGIN = 'plugin';
|
||||
export const TYPES_STORAGE_BUCKET = Object.freeze([TYPE_STORAGE_BUCKET_PLUGIN]);
|
||||
|
||||
export const TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3 = 'aws_s3';
|
||||
export const TYPES_STORAGE_BUCKET_PLUGIN = Object.freeze([
|
||||
TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3,
|
||||
]);
|
||||
|
||||
export default class StorageBucketModel extends GeneratedStorageBucketModel {
|
||||
/**
|
||||
* True if the storage bucket is a plugin.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isPlugin() {
|
||||
return this.type === 'plugin';
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the storage bucket is an unknown type.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isUnknown() {
|
||||
return (
|
||||
!TYPES_STORAGE_BUCKET.includes(this.type) ||
|
||||
(this.isPlugin &&
|
||||
!TYPES_STORAGE_BUCKET_PLUGIN.includes(this.plugin?.name))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the storage bucket plugin type is AWS.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isAWS() {
|
||||
return this.compositeType === 'aws_s3';
|
||||
}
|
||||
|
||||
/**
|
||||
* If the storage bucket is a plugin return `plugin.name`,
|
||||
* otherwise return the storage bucket type.
|
||||
* @type {string}
|
||||
*/
|
||||
get compositeType() {
|
||||
if (this.isUnknown) return 'unknown';
|
||||
return this.plugin.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets `type` to `plugin` and `plugin.name` to the specified type.
|
||||
*/
|
||||
set compositeType(type) {
|
||||
this.type = 'plugin';
|
||||
this.plugin = { name: type };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from 'api/models/storage-bucket';
|
||||
@@ -0,0 +1,80 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import { TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3 } from 'api/models/storage-bucket';
|
||||
|
||||
module('Unit | Model | storage bucket', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('storage-bucket', {});
|
||||
assert.ok(model);
|
||||
});
|
||||
|
||||
test('it has the isPlugin property and returns the expected values', async function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const modelPlugin = store.createRecord('storage-bucket', {
|
||||
type: 'plugin',
|
||||
plugin: {
|
||||
name: TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3,
|
||||
},
|
||||
});
|
||||
assert.true(modelPlugin.isPlugin);
|
||||
});
|
||||
|
||||
test('it has isUnknown property and returns the expected values', async function (assert) {
|
||||
assert.expect(2);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const modelA = store.createRecord('storage-bucket', {
|
||||
compositeType: TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3,
|
||||
});
|
||||
const modelB = store.createRecord('storage-bucket', {
|
||||
compositeType: 'no-such-type',
|
||||
});
|
||||
assert.false(modelA.isUnknown);
|
||||
assert.true(modelB.isUnknown);
|
||||
});
|
||||
|
||||
test('it has isAWS property and returns the expected values', async function (assert) {
|
||||
assert.expect(2);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const modelAws = store.createRecord('storage-bucket', {
|
||||
type: 'plugin',
|
||||
plugin: { name: TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3 },
|
||||
});
|
||||
const modelRandom = store.createRecord('storage-bucket', {
|
||||
plugin: { name: 'random' },
|
||||
});
|
||||
assert.true(modelAws.isAWS);
|
||||
assert.false(modelRandom.isAWS);
|
||||
});
|
||||
|
||||
test('get compositeType returns expected values', async function (assert) {
|
||||
assert.expect(2);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const modelA = store.createRecord('storage-bucket', {
|
||||
type: 'plugin',
|
||||
plugin: { name: TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3 },
|
||||
});
|
||||
const modelB = store.createRecord('storage-bucket', {
|
||||
type: 'plugin',
|
||||
plugin: { name: 'no-such-type' },
|
||||
});
|
||||
assert.strictEqual(modelA.compositeType, TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3);
|
||||
assert.strictEqual(modelB.compositeType, 'unknown');
|
||||
});
|
||||
|
||||
test('set compositeType sets expected values', async function (assert) {
|
||||
assert.expect(2);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const modelPlugin = store.createRecord('storage-bucket', {
|
||||
compositeType: TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3,
|
||||
});
|
||||
assert.strictEqual(modelPlugin.type, 'plugin');
|
||||
assert.strictEqual(
|
||||
modelPlugin.plugin.name,
|
||||
TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user