From 55dff321fad678c03aafaced2a77a2246d6ad8df Mon Sep 17 00:00:00 2001 From: ivy Date: Sat, 26 Aug 2023 13:08:10 -0700 Subject: [PATCH] feat: load s3 keys from env AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID --- ext/files.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ext/files.ts b/ext/files.ts index 5b8912b..b7d32f0 100644 --- a/ext/files.ts +++ b/ext/files.ts @@ -24,9 +24,9 @@ type R2Options = { type S3Options = { type: 's3' - endpoint: string - accessKeyId: string - secretAccessKey: string + endpoint?: string + accessKeyId?: string + secretAccessKey?: string } const awsClient = new AwsClient({ @@ -61,10 +61,16 @@ export const files = createExtension<{ switch (serve.type) { case 'r2': return handleR2Files(app, serve, prefix) - case 's3': - awsClient.accessKeyId = serve.accessKeyId - awsClient.secretAccessKey = serve.secretAccessKey + case 's3': { + const keyId = Deno.env.get('AWS_ACCESS_KEY_ID') ?? serve.accessKeyId + if (!keyId) throw new Error('AWS_ACCESS_KEY_ID is not set') + const accessKey = Deno.env.get('AWS_SECRET_ACCESS_KEY') ?? + serve.secretAccessKey + if (!accessKey) throw new Error('AWS_SECRET_ACCESS_KEY is not set') + awsClient.accessKeyId = keyId + awsClient.secretAccessKey = accessKey return handleS3Files(app, serve, prefix, request) + } case 'fs': default: return handleFsFiles(app, serve, prefix)