From 1d64d58bb87d5fe5039fe2efef6ffdf2bf1e59cb Mon Sep 17 00:00:00 2001 From: Christian Capeans Date: Fri, 10 Nov 2023 11:28:32 +0100 Subject: [PATCH] fix: make aws credentials optional --- .../upload-aws-s3/src/__tests__/utils.test.ts | 16 +++++++++++++--- packages/providers/upload-aws-s3/src/utils.ts | 3 +-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/providers/upload-aws-s3/src/__tests__/utils.test.ts b/packages/providers/upload-aws-s3/src/__tests__/utils.test.ts index 8aab32fd2f..c9244b373d 100644 --- a/packages/providers/upload-aws-s3/src/__tests__/utils.test.ts +++ b/packages/providers/upload-aws-s3/src/__tests__/utils.test.ts @@ -16,7 +16,7 @@ const defaultOptions = { describe('Utils', () => { describe('Extract credentials for V4 different aws provider configurations', () => { - test('[Legacy] Credentials directly in the options', async () => { + test('[Legacy] Credentials directly in the options', () => { const options: InitOptions = { accessKeyId, secretAccessKey, @@ -30,7 +30,7 @@ describe('Utils', () => { }); }); - test('[Legacy] credentials directly in s3Options', async () => { + test('[Legacy] credentials directly in s3Options', () => { const options: InitOptions = { s3Options: { accessKeyId, @@ -46,7 +46,7 @@ describe('Utils', () => { }); }); - test('Credentials in credentials object inside s3Options', async () => { + test('Credentials in credentials object inside s3Options', () => { const options: InitOptions = { s3Options: { credentials: { @@ -63,5 +63,15 @@ describe('Utils', () => { secretAccessKey, }); }); + test('Does not throw an error when are not present', () => { + const options: InitOptions = { + s3Options: { + ...defaultOptions, + }, + }; + const credentials = extractCredentials(options); + + expect(credentials).toEqual({}); + }); }); }); diff --git a/packages/providers/upload-aws-s3/src/utils.ts b/packages/providers/upload-aws-s3/src/utils.ts index 31e5f34ec6..0fcf30096e 100644 --- a/packages/providers/upload-aws-s3/src/utils.ts +++ b/packages/providers/upload-aws-s3/src/utils.ts @@ -114,6 +114,5 @@ export const extractCredentials = (options: InitOptions): AwsCredentialIdentity secretAccessKey: options.s3Options.credentials.secretAccessKey, }; } - - throw new Error("Couldn't find AWS credentials."); + return {}; };