Types for aws host catalogs (#2514)

assume role dynamic AWS credentials
This commit is contained in:
Dharini Jeeva authored and GitHub committed 2024-10-09 14:49:22 -07:00
1 parent 0d55812f64
commit 965e82473d
11 files changed
+538 -89

No files matched your search

+46 -25
View File
@@ -4,30 +4,53 @@
*/
import ApplicationSerializer from './application';
import {
TYPE_HOST_CATALOG_PLUGIN_AWS,
TYPE_HOST_CATALOG_PLUGIN_AZURE,
} from '../models/host-catalog';
const fieldsByType = {
aws: [
'disable_credential_rotation',
'region',
// These fields are Azure specific
const azureFields = [
'disable_credential_rotation',
'tenant_id',
'client_id',
'subscription_id',
'secret_id',
'secret_value',
];
// These fields are AWS specific, AWS provider now has two credentialTypes: static and dynamic [not to be confused with static and dynamic host-catalogs]
const AWSfieldsWithCredentialType = {
'static-credential': [
'access_key_id',
'secret_access_key',
'region',
'disable_credential_rotation',
'worker_filter',
],
azure: [
'dynamic-credential': [
'role_arn',
'role_external_id',
'role_session_name',
'role_tags',
'region',
'disable_credential_rotation',
'tenant_id',
'client_id',
'subscription_id',
'secret_id',
'secret_value',
'worker_filter',
],
};
export default class HostCatalogSerializer extends ApplicationSerializer {
// =methods
serialize(snapshot) {
const { compositeType } = snapshot.record;
const serialized = super.serialize(...arguments);
switch (snapshot.record.compositeType) {
// This is a hack to remove the worker_filter field from the serialized data if the compositeType is not AWS
// Ideally we should refactor the model to include the compositeType using `for` attribute
if (compositeType !== TYPE_HOST_CATALOG_PLUGIN_AWS) {
delete serialized.worker_filter;
}
switch (compositeType) {
case 'static':
return this.serializeStatic(...arguments);
default:
@@ -37,31 +60,28 @@ export default class HostCatalogSerializer extends ApplicationSerializer {
serializeAttribute(snapshot, json, key, attribute) {
const value = super.serializeAttribute(...arguments);
const { isPlugin, compositeType } = snapshot.record;
const { compositeType, credentialType, isPlugin } = snapshot.record;
const { options } = attribute;
// Delete any fields that don't belong to the compositeType
if (
isPlugin &&
json &&
options?.for &&
!options.for.includes(compositeType) &&
!fieldsByType[compositeType].includes(key)
) {
delete json[key];
}
const fields =
compositeType === TYPE_HOST_CATALOG_PLUGIN_AZURE
? azureFields
: AWSfieldsWithCredentialType[credentialType];
// Delete any nested attribute fields that don't belong to the record type
if (isPlugin && options.isNestedAttribute && json.attributes) {
if (!fieldsByType[compositeType].includes(key)) {
if (!fields.includes(key)) {
delete json.attributes[key];
}
}
// Delete any secret fields that don't belong to the record type
if (isPlugin && options.isNestedSecret && json.secrets) {
if (!fieldsByType[compositeType].includes(key)) {
if (!fields.includes(key)) {
delete json.secrets[key];
if (json['secrets'] && Object.keys(json.secrets).length === 0) {
delete json.secrets;
}
}
}
return value;
@@ -72,6 +92,7 @@ export default class HostCatalogSerializer extends ApplicationSerializer {
// Delete unnecessary fields for static host-catalog
delete serialized.attributes;
delete serialized.secrets;
delete serialized.worker_filter;
return serialized;
}
}