Allow AWS SDK use AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY

This commit is contained in:
Philipinho
2024-07-07 09:24:19 +01:00
parent 7383673636
commit 4af3a54649
3 changed files with 22 additions and 9 deletions

View File

@ -41,20 +41,34 @@ export const storageDriverConfigProvider = {
};
case StorageOption.S3:
return {
const s3Config = {
driver,
config: {
region: environmentService.getAwsS3Region(),
endpoint: environmentService.getAwsS3Endpoint(),
bucket: environmentService.getAwsS3Bucket(),
baseUrl: environmentService.getAwsS3Url(),
credentials: {
accessKeyId: environmentService.getAwsS3AccessKeyId(),
secretAccessKey: environmentService.getAwsS3SecretAccessKey(),
},
credentials: undefined,
},
};
/**
* This makes use of AWS_S3_ACCESS_KEY_ID and AWS_S3_SECRET_ACCESS_KEY if present,
* If not present, it makes it lenient for the AWS SDK to use
* AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY if they are present in the environment
*/
if (
environmentService.getAwsS3AccessKeyId() &&
environmentService.getAwsS3SecretAccessKey()
) {
s3Config.config.credentials = {
accessKeyId: environmentService.getAwsS3AccessKeyId(),
secretAccessKey: environmentService.getAwsS3SecretAccessKey(),
};
}
return s3Config;
default:
throw new Error(`Unknown storage driver: ${driver}`);
}