From 12bb8203c2a0936f833e2c6e629a1dc3d0983015 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 21 Jan 2022 14:45:21 -0800 Subject: [PATCH] Change mirage attributes to factory --- .../addon/generated/models/host-catalog.js | 9 --- addons/api/mirage/factories/host-catalog.js | 21 +++++++ .../generated/factories/host-catalog.js | 60 +------------------ 3 files changed, 22 insertions(+), 68 deletions(-) diff --git a/addons/api/addon/generated/models/host-catalog.js b/addons/api/addon/generated/models/host-catalog.js index f786b4568..0591352e2 100644 --- a/addons/api/addon/generated/models/host-catalog.js +++ b/addons/api/addon/generated/models/host-catalog.js @@ -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; diff --git a/addons/api/mirage/factories/host-catalog.js b/addons/api/mirage/factories/host-catalog.js index 75bcc3928..f7c82a20d 100644 --- a/addons/api/mirage/factories/host-catalog.js +++ b/addons/api/mirage/factories/host-catalog.js @@ -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; diff --git a/addons/api/mirage/generated/factories/host-catalog.js b/addons/api/mirage/generated/factories/host-catalog.js index 14dcbb306..20601e2f3 100644 --- a/addons/api/mirage/generated/factories/host-catalog.js +++ b/addons/api/mirage/generated/factories/host-catalog.js @@ -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); - } - }, });