Icu 11022 update dynamic credentials in sb form (#1901)

This commit is contained in:
Dharini Jeeva authored and GitHub committed 2023-09-18 14:23:30 -07:00
1 parent 4910070c95
commit 78d1e09a0d
8 files changed
+112 -33

No files matched your search

@@ -73,12 +73,6 @@ export default class GeneratedStorageBucketModel extends BaseModel {
})
region;
@attr('string', {
readOnly: true,
isNestedAttribute: true,
})
secrets_hmac;
@attr('boolean', {
isNestedAttribute: true,
description: 'If set to `true`, credential rotation is not performed.',
@@ -120,7 +114,6 @@ export default class GeneratedStorageBucketModel extends BaseModel {
@attr('object-as-array', {
isNestedAttribute: true,
description: 'The role tags to use.',
useLabels: true,
})
role_tags;
}
+1 -1
View File
@@ -36,7 +36,7 @@ export default class StorageBucketModel extends GeneratedStorageBucketModel {
* @type {string}
*/
get credentialType() {
if (this.role_arn) {
if (this.role_arn && !this.access_key_id) {
return TYPE_CREDENTIAL_DYNAMIC;
} else {
return TYPE_CREDENTIAL_STATIC;
+42 -9
View File
@@ -4,29 +4,62 @@
*/
import ApplicationSerializer from './application';
import { TYPE_CREDENTIAL_DYNAMIC } from '../models/storage-bucket';
const fieldsByCredentialType = {
static: [
'access_key_id',
'secret_access_key',
'region',
'disable_credential_rotation',
],
dynamic: [
'role_arn',
'role_external_id',
'role_session_name',
'role_tags',
'disable_credential_rotation',
'region',
],
};
export default class StorageBucketSerializer extends ApplicationSerializer {
serialize(snapshot) {
const serialized = super.serialize(...arguments);
//Dynamic credentials do not allow credential rotation, and the API requires this field to be
//sent along with the dynamic credential fields
if (serialized.attributes.role_arn) {
serialized.attributes.disable_credential_rotation = true;
}
const { credentialType } = snapshot.record;
if (!snapshot.record.isNew) {
delete serialized.bucket_name;
delete serialized.bucket_prefix;
}
if (credentialType === TYPE_CREDENTIAL_DYNAMIC) {
serialized.attributes.disable_credential_rotation = true;
}
return serialized;
}
serializeAttribute(snapshot, json, key, attribute) {
const value = super.serializeAttribute(...arguments);
const { credentialType } = snapshot.record;
const { options } = attribute;
// This deletes any fields that don't belong to the record's credential type
if (options.isNestedAttribute && json.attributes) {
// The key must be included in the fieldsByType list above
if (!fieldsByCredentialType[credentialType].includes(key))
//API requires these fields to be null
json.attributes[key] = null;
}
return value;
}
normalize(typeClass, hash, ...rest) {
const normalizedHash = structuredClone(hash);
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
// Remove secret fields so we don't track them after creating/updating
normalized.data.attributes.access_key_id = null;
normalized.data.attributes.secret_access_key = null;
return normalized;
if (normalizedHash?.secrets?.access_key_id) {
delete normalizedHash.secrets.access_key_id;
delete normalizedHash.secrets.secret_access_key;
}
return super.normalize(typeClass, normalizedHash, ...rest);
}
}