feat: 🎸 Add mirage data for storage buckets (#91)
* feat: 🎸 Add mirage data for storage buckets ✅ Closes: ICU-8074
This commit is contained in:
1 parent
4d62e67f2a
commit
cd30f4e5ce
7 files changed
+107
-2
No files matched your search
@@ -634,8 +634,7 @@ function routes() {
|
||||
this.patch('/managed-groups/:id');
|
||||
this.del('/managed-groups/:id');
|
||||
|
||||
// worker
|
||||
|
||||
// workers
|
||||
this.get(
|
||||
'/workers',
|
||||
({ workers }, { queryParams: { scope_id: scopeId } }) => {
|
||||
@@ -656,6 +655,30 @@ function routes() {
|
||||
return workers.create(newWorker.attrs);
|
||||
});
|
||||
|
||||
// storage-buckets
|
||||
this.get(
|
||||
'/storage-buckets',
|
||||
({ storageBuckets }, { queryParams: { scope_id: scopeId } }) => {
|
||||
return storageBuckets.where({ scopeId });
|
||||
}
|
||||
);
|
||||
this.get('/storage-buckets/:id');
|
||||
this.del('/storage-buckets/:id');
|
||||
this.patch('/storage-buckets/:id');
|
||||
this.post(
|
||||
'/storage-buckets',
|
||||
({ storageBuckets }, { queryParams: { plugin_name } }) => {
|
||||
const attrs = this.normalizedRequestAttrs();
|
||||
if (plugin_name) {
|
||||
attrs.type = 'plugin';
|
||||
attrs.plugin = {
|
||||
name: plugin_name,
|
||||
};
|
||||
}
|
||||
return storageBuckets.create(attrs);
|
||||
}
|
||||
);
|
||||
|
||||
/* Uncomment the following line and the Response import above
|
||||
* Then change the response code to simulate error responses.
|
||||
* this.get('/scopes', () => new Response(505));
|
||||
|
||||
@@ -30,6 +30,7 @@ export default factory.extend({
|
||||
'credential-stores': ['create', 'list'],
|
||||
'auth-methods': ['create', 'list'],
|
||||
'host-catalogs': ['create', 'list'],
|
||||
'storage-buckets': ['create', 'list'],
|
||||
};
|
||||
|
||||
// Worker permissions only available on the global scope
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import factory from '../generated/factories/storage-bucket';
|
||||
import permissions from '../helpers/permissions';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import generateId from '../helpers/id';
|
||||
import {
|
||||
TYPES_STORAGE_BUCKET as types,
|
||||
TYPES_STORAGE_BUCKET_PLUGIN,
|
||||
TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3,
|
||||
} from 'api/models/storage-bucket';
|
||||
|
||||
// Represents known plugin types, except "foobar" which models the possibility
|
||||
// of receiving an _unknown_ type, which the UI must handle gracefully.
|
||||
const pluginTypes = [...TYPES_STORAGE_BUCKET_PLUGIN, 'foobar'];
|
||||
|
||||
export default factory.extend({
|
||||
id: () => generateId('sb_'),
|
||||
|
||||
// Cycle through available types
|
||||
type: (i) => types[i % types.length],
|
||||
|
||||
authorized_actions: () =>
|
||||
permissions.authorizedActionsFor('storage-bucket') || [
|
||||
'no-op',
|
||||
'read',
|
||||
'update',
|
||||
'delete',
|
||||
],
|
||||
|
||||
plugin: function (i) {
|
||||
if (this.type === 'plugin') {
|
||||
return {
|
||||
id: `plugin-id-${i}`,
|
||||
name: pluginTypes[i % pluginTypes.length],
|
||||
description: faker.random.words(),
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
attributes() {
|
||||
switch (this.plugin?.name) {
|
||||
case TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3:
|
||||
return {
|
||||
region: `us-${faker.address.cardinalDirection()}-${faker.datatype.number(
|
||||
{
|
||||
max: 9,
|
||||
}
|
||||
)}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Factory } from 'miragejs';
|
||||
import { faker } from '@faker-js/faker';
|
||||
|
||||
/**
|
||||
* GeneratedStorageBucketModelFactory
|
||||
*/
|
||||
export default Factory.extend({
|
||||
type: 'plugin',
|
||||
name: () => faker.random.words(),
|
||||
description: () => faker.random.words(),
|
||||
created_time: () => faker.date.recent(),
|
||||
updated_time: () => faker.date.recent(),
|
||||
version: () => faker.datatype.number(),
|
||||
bucket_name: () => faker.internet.domainWord(),
|
||||
bucket_prefix: () => faker.system.directoryPath(),
|
||||
worker_filter: () => faker.random.words(),
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
import { belongsTo } from 'miragejs';
|
||||
import Model from './base';
|
||||
export default Model.extend({
|
||||
scope: belongsTo(),
|
||||
});
|
||||
@@ -109,4 +109,8 @@ export default function (server) {
|
||||
|
||||
// Workers
|
||||
server.createList('worker', 3, { scope: globalScope });
|
||||
|
||||
// Session Recordings and Storage Buckets
|
||||
server.createList('storage-bucket', 3, { scope: globalScope });
|
||||
server.createList('storage-bucket', 2, { scope: orgScope });
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import ApplicationSerializer from './application';
|
||||
export default ApplicationSerializer.extend({
|
||||
modelName: 'storage-bucket',
|
||||
});
|
||||
Reference in new issue
Block a user