From 7b9538dbdac7af87850d63074075e9f6c98c9cbb Mon Sep 17 00:00:00 2001 From: Andreas Wittig Date: Mon, 3 Jan 2022 11:06:58 +0100 Subject: [PATCH] Adding support for AWS IAM role credentials --- libs/server/store/index.ts | 4 ++-- libs/server/store/providers/s3.ts | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libs/server/store/index.ts b/libs/server/store/index.ts index 432025ccd..c22884a7e 100644 --- a/libs/server/store/index.ts +++ b/libs/server/store/index.ts @@ -3,8 +3,8 @@ import { StoreS3 } from './providers/s3' export function createStore() { return new StoreS3({ - accessKey: getEnv('STORE_ACCESS_KEY', undefined, true), - secretKey: getEnv('STORE_SECRET_KEY', undefined, true), + accessKey: getEnv('STORE_ACCESS_KEY'), + secretKey: getEnv('STORE_SECRET_KEY'), endPoint: getEnv('STORE_END_POINT'), bucket: getEnv('STORE_BUCKET', 'notea'), region: getEnv('STORE_REGION', 'us-east-1'), diff --git a/libs/server/store/providers/s3.ts b/libs/server/store/providers/s3.ts index bc5cf7bf4..faf1cf02d 100644 --- a/libs/server/store/providers/s3.ts +++ b/libs/server/store/providers/s3.ts @@ -40,11 +40,14 @@ export class StoreS3 extends StoreProvider { forcePathStyle: config.pathStyle, region: config.region, endpoint: config.endPoint, - credentials: { + credentials: ((config.accessKey && config.secretKey) ? { accessKeyId: config.accessKey, secretAccessKey: config.secretKey, - }, + }: undefined), }) + if (!config.accessKey || !config.secretKey) { + console.log('[Notea] Environment variables STORE_ACCESS_KEY or STORE_SECRET_KEY is missing. Trying to use IAM role credentials instead ...') + } this.config = config }