From fade886b7a666269c0e2838cca87bca82301b371 Mon Sep 17 00:00:00 2001 From: Ryan Brereton Date: Mon, 26 Sep 2022 13:40:33 +0930 Subject: [PATCH 1/2] feat: fallback to default AWS credential chain --- .changeset/silver-shirts-remain.md | 5 +++++ packages/core/src/lib/assets/s3.ts | 4 ++-- packages/core/src/types/config/index.ts | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .changeset/silver-shirts-remain.md diff --git a/.changeset/silver-shirts-remain.md b/.changeset/silver-shirts-remain.md new file mode 100644 index 00000000000..a0b475b70bf --- /dev/null +++ b/.changeset/silver-shirts-remain.md @@ -0,0 +1,5 @@ +--- +'@keystone-6/core': minor +--- + +Allow falling back to default AWS credential provider diff --git a/packages/core/src/lib/assets/s3.ts b/packages/core/src/lib/assets/s3.ts index 412697a7deb..378df4add35 100644 --- a/packages/core/src/lib/assets/s3.ts +++ b/packages/core/src/lib/assets/s3.ts @@ -96,10 +96,10 @@ export function getS3AssetsEndpoint(storageConfig: StorageConfig & { kind: 's3' function s3AssetsCommon(storageConfig: StorageConfig & { kind: 's3' }) { const s3 = new S3({ - credentials: { + credentials: storageConfig.accessKeyId && storageConfig.secretAccessKey ? { accessKeyId: storageConfig.accessKeyId, secretAccessKey: storageConfig.secretAccessKey, - }, + } : undefined, region: storageConfig.region, endpoint: storageConfig.endpoint, forcePathStyle: storageConfig.forcePathStyle, diff --git a/packages/core/src/types/config/index.ts b/packages/core/src/types/config/index.ts index d2dc4327a7e..c0d5def20b2 100644 --- a/packages/core/src/types/config/index.ts +++ b/packages/core/src/types/config/index.ts @@ -74,9 +74,9 @@ export type StorageConfig = ( /** Your s3 instance's region */ region: string; /** An access Key ID with write access to your S3 instance */ - accessKeyId: string; + accessKeyId?: string; /** The secret access key that gives permissions to your access Key Id */ - secretAccessKey: string; + secretAccessKey?: string; /** An endpoint to use - to be provided if you are not using AWS as your endpoint */ endpoint?: string; /** If true, will force the 'old' S3 path style of putting bucket name at the start of the pathname of the URL */ From d965f25359b4ba440ebc0c30890a64b73d6648fe Mon Sep 17 00:00:00 2001 From: Ryan Brereton Date: Mon, 26 Sep 2022 16:45:54 +0930 Subject: [PATCH 2/2] chore: code style --- packages/core/src/lib/assets/s3.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/core/src/lib/assets/s3.ts b/packages/core/src/lib/assets/s3.ts index 378df4add35..b905218741f 100644 --- a/packages/core/src/lib/assets/s3.ts +++ b/packages/core/src/lib/assets/s3.ts @@ -96,10 +96,13 @@ export function getS3AssetsEndpoint(storageConfig: StorageConfig & { kind: 's3' function s3AssetsCommon(storageConfig: StorageConfig & { kind: 's3' }) { const s3 = new S3({ - credentials: storageConfig.accessKeyId && storageConfig.secretAccessKey ? { - accessKeyId: storageConfig.accessKeyId, - secretAccessKey: storageConfig.secretAccessKey, - } : undefined, + credentials: + storageConfig.accessKeyId && storageConfig.secretAccessKey + ? { + accessKeyId: storageConfig.accessKeyId, + secretAccessKey: storageConfig.secretAccessKey, + } + : undefined, region: storageConfig.region, endpoint: storageConfig.endpoint, forcePathStyle: storageConfig.forcePathStyle,