Change mirage attributes to factory

This commit is contained in:
Carlos Alcaide Corvo committed 2022-01-21 14:45:21 -08:00
1 parent 614be72a6e
commit 12bb8203c2
3 files changed
+22 -68

No files matched your search

@@ -44,11 +44,6 @@ export default class GeneratedHostCatalogModel extends BaseModel {
})
attributes;
@attr({
description: 'Secrets specific to the plugin type',
})
secrets;
@attr('number', {
description: 'Current version number of this resource.',
})
@@ -78,14 +73,12 @@ export default class GeneratedHostCatalogModel extends BaseModel {
@attr('string', {
isNestedSecret: true,
writeOnly: true,
description: '',
})
access_key_id;
@attr('string', {
isNestedSecret: true,
writeOnly: true,
description: '',
})
secret_access_key;
@@ -112,14 +105,12 @@ export default class GeneratedHostCatalogModel extends BaseModel {
@attr('string', {
isNestedSecret: true,
writeOnly: true,
description: '',
})
secret_id;
@attr('string', {
isNestedSecret: true,
writeOnly: true,
description: '',
})
secret_value;
@@ -1,6 +1,7 @@
import factory from '../generated/factories/host-catalog';
import { trait } from 'ember-cli-mirage';
import permissions from '../helpers/permissions';
import { datatype, address } from 'faker';
export default factory.extend({
authorized_actions: () =>
@@ -16,6 +17,26 @@ export default factory.extend({
'host-sets': ['create', 'list'],
};
},
attributes() {
if (this.plugin) {
switch (this.plugin.name) {
case 'aws':
return {
tenant_id: datatype.hexaDecimal(6),
client_id: datatype.hexaDecimal(6),
subscription_id: datatype.hexaDecimal(8),
secret_id: datatype.hexaDecimal(6),
secret_value: datatype.string(12),
};
case 'azure':
return {
region: address.state(),
access_key_id: datatype.hexaDecimal(8),
secret_access_key: datatype.string(12),
};
}
}
},
withChildren: trait({
afterCreate(hostCatalog, server) {
const { scope, type } = hostCatalog;
@@ -1,22 +1,6 @@
import { Factory } from 'ember-cli-mirage';
import { random, date, datatype, address } from 'faker';
import { random, date, datatype } from 'faker';
/**
*
* @param {object} plugin
* @returns
*/
function isAzurePlugin(plugin) {
if (plugin && plugin.name === 'azure') {
return true;
}
}
function isAwsPlugin(plugin) {
if (plugin && plugin.name === 'aws') {
return true;
}
}
/**
* GeneratedHostCatalogModelFactory
*/
@@ -37,46 +21,4 @@ export default Factory.extend({
}
},
disable_credential_rotation: () => datatype.boolean(),
// Azure specific fields
region: function () {
if (isAzurePlugin(this.plugin)) {
return address.state();
}
},
access_key_id: function () {
if (isAzurePlugin(this.plugin)) {
return datatype.hexaDecimal(8);
}
},
secret_access_key: function () {
if (isAzurePlugin(this.plugin)) {
return datatype.string(12);
}
},
// AWS specific fields
tenant_id: function () {
if (isAwsPlugin(this.plugin)) {
return datatype.hexaDecimal(6);
}
},
client_id: function () {
if (isAwsPlugin(this.plugin)) {
return datatype.hexaDecimal(6);
}
},
subscription_id: function () {
if (isAwsPlugin(this.plugin)) {
return datatype.hexaDecimal(8);
}
},
secret_id: function () {
if (isAwsPlugin(this.plugin)) {
return datatype.hexaDecimal(6);
}
},
secret_value: function () {
if (isAwsPlugin(this.plugin)) {
return datatype.string(12);
}
},
});