From d53cfbcc3318e15ee36ee46515c6cb72446bfd8c Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 14 Feb 2022 11:14:52 -0500 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20simplify=20neste?= =?UTF-8?q?d=20fields=20normalization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/serializers/application.js | 23 ++++++++------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/addons/api/addon/serializers/application.js b/addons/api/addon/serializers/application.js index dcc33eff6..0b20dd128 100644 --- a/addons/api/addon/serializers/application.js +++ b/addons/api/addon/serializers/application.js @@ -234,11 +234,13 @@ export default class ApplicationSerializer extends RESTSerializer { */ normalizeNestedAttributes(typeClass, hash) { typeClass.attributes.forEach((attribute) => { - const { isNestedAttribute } = attribute.options; - const attributeValue = hash.attributes?.[attribute.name]; - if (isNestedAttribute && typeof attributeValue != 'undefined') { - hash[attribute.name] = attributeValue; - } + const { + name, + options: { isNestedAttribute }, + } = attribute; + const value = hash.attributes?.[name]; + const isUndefined = value === undefined; + if (isNestedAttribute && !isUndefined) hash[name] = value; }); return hash; } @@ -261,15 +263,8 @@ export default class ApplicationSerializer extends RESTSerializer { name, options: { isNestedSecret }, } = attribute; - const attributeValue = hash.secrets?.[name]; - - // FIXME: This could be improved - if (isNestedSecret) { - hash[name] = null; - if (typeof attributeValue != 'undefined') { - hash[name] = attributeValue; - } - } + const value = hash.secrets?.[name]; + if (isNestedSecret) hash[name] = value; }); return hash; } From ac215e200f32772050054e28496d2fca45dde9a6 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 14 Feb 2022 11:24:58 -0500 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20simplify=20host?= =?UTF-8?q?=20catalog=20modeling=20and=20normalization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/generated/models/host-catalog.js | 5 ----- addons/api/addon/serializers/host-catalog.js | 8 -------- addons/api/tests/unit/serializers/host-catalog-test.js | 8 -------- 3 files changed, 21 deletions(-) diff --git a/addons/api/addon/generated/models/host-catalog.js b/addons/api/addon/generated/models/host-catalog.js index 0591352e2..660711a70 100644 --- a/addons/api/addon/generated/models/host-catalog.js +++ b/addons/api/addon/generated/models/host-catalog.js @@ -39,11 +39,6 @@ export default class GeneratedHostCatalogModel extends BaseModel { }) disabled; - @attr({ - description: 'Attributes specific to the catalog type', - }) - attributes; - @attr('number', { description: 'Current version number of this resource.', }) diff --git a/addons/api/addon/serializers/host-catalog.js b/addons/api/addon/serializers/host-catalog.js index f5d1cd983..77c78c680 100644 --- a/addons/api/addon/serializers/host-catalog.js +++ b/addons/api/addon/serializers/host-catalog.js @@ -1,5 +1,4 @@ import ApplicationSerializer from './application'; -import { copy } from 'ember-copy'; const fieldsByType = { aws: [ @@ -57,11 +56,4 @@ export default class HostCatalogSerializer extends ApplicationSerializer { delete serialized.secrets; return serialized; } - - normalize(typeClass, hash, ...rest) { - let normalizedHash = copy(hash, true); - const normalized = super.normalize(typeClass, normalizedHash, ...rest); - delete normalized.data.attributes.attributes; - return normalized; - } } diff --git a/addons/api/tests/unit/serializers/host-catalog-test.js b/addons/api/tests/unit/serializers/host-catalog-test.js index 2811dea39..8b1af8c94 100644 --- a/addons/api/tests/unit/serializers/host-catalog-test.js +++ b/addons/api/tests/unit/serializers/host-catalog-test.js @@ -190,10 +190,6 @@ module('Unit | Serializer | host catalog', function (hooks) { description: 'Test description', authorized_actions: ['no-op'], type: 'static', - access_key_id: null, - secret_access_key: null, - secret_id: null, - secret_value: null, }, relationships: {}, }, @@ -249,8 +245,6 @@ module('Unit | Serializer | host catalog', function (hooks) { region: 'Illinois', access_key_id: '0xF3B0a6f8', secret_access_key: 'zq{2:IVc8@W^', - secret_id: null, - secret_value: null, }, relationships: {}, }, @@ -310,8 +304,6 @@ module('Unit | Serializer | host catalog', function (hooks) { client_id: 'client', tenant_id: 'tenant', subscription_id: 'subscription', - access_key_id: null, - secret_access_key: null, }, relationships: {}, }, From 93fd52954f2f4127ba749591e480772b618a068a Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 14 Feb 2022 11:50:39 -0500 Subject: [PATCH 3/5] =?UTF-8?q?chore:=20=F0=9F=A4=96=20explicitly=20set=20?= =?UTF-8?q?secrets=20to=20null=20when=20missing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/serializers/application.js | 2 +- addons/api/tests/unit/serializers/host-catalog-test.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/api/addon/serializers/application.js b/addons/api/addon/serializers/application.js index 0b20dd128..8f519e8e2 100644 --- a/addons/api/addon/serializers/application.js +++ b/addons/api/addon/serializers/application.js @@ -264,7 +264,7 @@ export default class ApplicationSerializer extends RESTSerializer { options: { isNestedSecret }, } = attribute; const value = hash.secrets?.[name]; - if (isNestedSecret) hash[name] = value; + if (isNestedSecret) hash[name] = value || null; }); return hash; } diff --git a/addons/api/tests/unit/serializers/host-catalog-test.js b/addons/api/tests/unit/serializers/host-catalog-test.js index 8b1af8c94..2811dea39 100644 --- a/addons/api/tests/unit/serializers/host-catalog-test.js +++ b/addons/api/tests/unit/serializers/host-catalog-test.js @@ -190,6 +190,10 @@ module('Unit | Serializer | host catalog', function (hooks) { description: 'Test description', authorized_actions: ['no-op'], type: 'static', + access_key_id: null, + secret_access_key: null, + secret_id: null, + secret_value: null, }, relationships: {}, }, @@ -245,6 +249,8 @@ module('Unit | Serializer | host catalog', function (hooks) { region: 'Illinois', access_key_id: '0xF3B0a6f8', secret_access_key: 'zq{2:IVc8@W^', + secret_id: null, + secret_value: null, }, relationships: {}, }, @@ -304,6 +310,8 @@ module('Unit | Serializer | host catalog', function (hooks) { client_id: 'client', tenant_id: 'tenant', subscription_id: 'subscription', + access_key_id: null, + secret_access_key: null, }, relationships: {}, }, From 83cf084ee683fcdf405cfe606ea195477928ba9d Mon Sep 17 00:00:00 2001 From: dharini Date: Mon, 14 Feb 2022 12:34:05 -0800 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20address?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/admin/app/components/form/host/static/index.hbs | 2 +- .../scopes/scope/host-catalogs/host-catalog/hosts/index.hbs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/admin/app/components/form/host/static/index.hbs b/ui/admin/app/components/form/host/static/index.hbs index 9b39cdb26..352cf1089 100644 --- a/ui/admin/app/components/form/host/static/index.hbs +++ b/ui/admin/app/components/form/host/static/index.hbs @@ -56,7 +56,7 @@ - {{host.attributes.address}} + {{host.address}} {{/each}} From b15c8b056f7a1ab8a2a0fff57c34620013e64571 Mon Sep 17 00:00:00 2001 From: dharini Date: Mon, 14 Feb 2022 12:55:07 -0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=F0=9F=90=9B=20error=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/admin/app/components/form/host/static/index.hbs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/admin/app/components/form/host/static/index.hbs b/ui/admin/app/components/form/host/static/index.hbs index 352cf1089..d86c04f1c 100644 --- a/ui/admin/app/components/form/host/static/index.hbs +++ b/ui/admin/app/components/form/host/static/index.hbs @@ -58,14 +58,14 @@ @type='text' @value={{@model.address}} @label={{t 'form.address.label'}} - @error={{@model.errors.name}} + @error={{@model.errors.address}} @helperText={{t 'form.address.help'}} readonly={{false}} as |field| > - {{#if @model.errors.name}} + {{#if @model.errors.address}} - {{#each @model.errors.name as |error|}} + {{#each @model.errors.address as |error|}} {{error.message}} {{/each}}