chore: 🤖 migrate host catalog and host set list wrapper fields to key value (#3276)

This commit is contained in:
Dharini committed 2026-06-03 16:36:29 -07:00
1 parent 4e2b779d96
commit 0e223ded8f
26 files changed
+512 -388

No files matched your search

@@ -76,6 +76,16 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsIndexController e
isNew ? 'notifications.create-success' : 'notifications.save-success',
)
async save(hostSet) {
if (hostSet.preferred_endpoints) {
hostSet.preferred_endpoints = hostSet.preferred_endpoints.filter((item) =>
item.value?.trim(),
);
}
if (hostSet.filters) {
hostSet.filters = hostSet.filters.filter((item) => item.value?.trim());
}
// Fetch newest host set as updates to host set attributes cause an async db update which
// updates the version again and can cause a version mismatch if the host set is updated
// again and we haven't fetched the newest version.
@@ -138,9 +148,15 @@ export default class ScopesScopeHostCatalogsHostCatalogHostSetsIndexController e
hostSet.preferred_endpoints = structuredClone(
hostSet.preferred_endpoints,
);
if (hostSet.preferred_endpoints.length === 0) {
hostSet.preferred_endpoints = [{ value: '' }];
}
}
if (hostSet.filters) {
hostSet.filters = structuredClone(hostSet.filters);
if (hostSet.filters.length === 0) {
hostSet.filters = [{ value: '' }];
}
}
}
@@ -10,7 +10,11 @@ import { action } from '@ember/object';
import { loading } from 'ember-loading';
import { confirm } from 'core/decorators/confirm';
import { notifySuccess, notifyError } from 'core/decorators/notify';
import { TYPE_CREDENTIAL_STATIC } from 'api/models/host-catalog';
import {
TYPE_CREDENTIAL_DYNAMIC,
TYPE_CREDENTIAL_STATIC,
TYPE_HOST_CATALOG_PLUGIN_AWS,
} from 'api/models/host-catalog';
export default class ScopesScopeHostCatalogsIndexController extends Controller {
// =services
@@ -60,6 +64,19 @@ export default class ScopesScopeHostCatalogsIndexController extends Controller {
return this.intl.t(description, { resource });
}
/**
* Generates one empty role_tags row for AWS host catalogs when the field is empty.
* @param {HostCatalogModel} hostCatalog
*/
generateAwsRoleTagsRowIfEmpty(hostCatalog) {
if (
hostCatalog.compositeType === TYPE_HOST_CATALOG_PLUGIN_AWS &&
(!hostCatalog.role_tags || hostCatalog.role_tags.length === 0)
) {
hostCatalog.role_tags = [{ key: '', value: '' }];
}
}
// =actions
/**
@@ -96,6 +113,12 @@ export default class ScopesScopeHostCatalogsIndexController extends Controller {
isNew ? 'notifications.create-success' : 'notifications.save-success',
)
async save(hostCatalog) {
if (hostCatalog.role_tags) {
hostCatalog.role_tags = hostCatalog.role_tags.filter((item) =>
item.key?.trim(),
);
}
// If the role_arn is empty, then the credential type should be static
if (!hostCatalog.role_arn) {
hostCatalog.credentialType = TYPE_CREDENTIAL_STATIC;
@@ -145,6 +168,25 @@ export default class ScopesScopeHostCatalogsIndexController extends Controller {
@action
changeCredentialType(hostCatalog, credentialType) {
hostCatalog.credentialType = credentialType;
if (credentialType === TYPE_CREDENTIAL_DYNAMIC) {
this.generateAwsRoleTagsRowIfEmpty(hostCatalog);
}
}
/**
* Prepares key-value array fields for editing.
* @param {HostCatalogModel} hostCatalog
*/
@action
edit(hostCatalog) {
if (hostCatalog.role_tags) {
hostCatalog.role_tags = structuredClone(hostCatalog.role_tags);
}
if (hostCatalog.credentialType === TYPE_CREDENTIAL_DYNAMIC) {
this.generateAwsRoleTagsRowIfEmpty(hostCatalog);
}
}
/**