feat: 🎸 add support for dynamic credentials in storage bucket (#1897)

* feat: 🎸 add support for dynamic credentials in storage bucket
This commit is contained in:
Dharini Jeeva authored and GitHub committed 2023-09-18 13:26:38 -07:00
1 parent 3cb8417a89
commit 4910070c95
13 files changed
+420 -96

No files matched your search

+21
View File
@@ -13,6 +13,14 @@ export const TYPES_STORAGE_BUCKET_PLUGIN = Object.freeze([
TYPE_STORAGE_BUCKET_PLUGIN_AWS_S3,
]);
export const TYPE_CREDENTIAL_STATIC = 'static';
export const TYPE_CREDENTIAL_DYNAMIC = 'dynamic';
export const TYPES_CREDENTIALS = Object.freeze([
TYPE_CREDENTIAL_STATIC,
TYPE_CREDENTIAL_DYNAMIC,
]);
export default class StorageBucketModel extends GeneratedStorageBucketModel {
/**
* True if the storage bucket is a plugin.
@@ -22,6 +30,19 @@ export default class StorageBucketModel extends GeneratedStorageBucketModel {
return this.type === TYPE_STORAGE_BUCKET_PLUGIN;
}
/**
* If the storage bucket has role_arn, return dynamic
* otherwise return the default static type.
* @type {string}
*/
get credentialType() {
if (this.role_arn) {
return TYPE_CREDENTIAL_DYNAMIC;
} else {
return TYPE_CREDENTIAL_STATIC;
}
}
/**
* True if the storage bucket is an unknown type.
* @type {boolean}
@@ -8,6 +8,11 @@ import ApplicationSerializer from './application';
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;
}
if (!snapshot.record.isNew) {
delete serialized.bucket_name;
delete serialized.bucket_prefix;