Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
feat: load s3 keys from env
Browse files Browse the repository at this point in the history
AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID
  • Loading branch information
ivy committed Aug 26, 2023
1 parent 29e6706 commit 55dff32
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions ext/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 55dff32

Please sign in to comment.