Skip to content

Commit fb0914d

Browse files
IhorMasechkoIhor Masechko
andauthored
feat: S3 credential resolution via APOS_S3_SECRET or AWS default chain (#256)
feat: S3 credential resolution via APOS_S3_SECRET or AWS default chain <!-- This is an auto-generated comment: release notes by coderabbit.ai --> Refactors S3 credential configuration in the uploadfs module by introducing a centralized uploadfsOptions object populated from environment variables. It sets HTTPS flag, CDN settings, bucket/region/endpoint/style, and conditionally adds secret and key when APOS_S3_SECRET is present. Credentials otherwise rely on the AWS default credential chain via omission of inline keys for uploads. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Ihor Masechko <ihormasechko@Ihors-MacBook-Air.local>
1 parent 97c04d9 commit fb0914d

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

  • website/modules/@apostrophecms/uploadfs

website/modules/@apostrophecms/uploadfs/index.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
const { getEnv } = require('../../../utils/env');
22

3+
const aposS3Secret = process.env.APOS_S3_SECRET;
4+
const aposS3Https = getEnv('APOS_S3_HTTPS');
5+
6+
const uploadfsOptions = {
7+
storage: 's3',
8+
bucket: getEnv('APOS_S3_BUCKET'),
9+
region: getEnv('APOS_S3_REGION'),
10+
endpoint: getEnv('APOS_S3_ENDPOINT'),
11+
style: getEnv('APOS_S3_STYLE'),
12+
https: aposS3Https.toLowerCase() === 'true',
13+
cdn: {
14+
enabled: true,
15+
url: getEnv('APOS_CDN_URL'),
16+
},
17+
};
18+
19+
if (aposS3Secret) {
20+
uploadfsOptions.secret = aposS3Secret;
21+
uploadfsOptions.key = getEnv('APOS_S3_KEY');
22+
}
23+
324
const res = {
425
options: {
5-
uploadfs: {
6-
storage: 's3',
7-
// Get your credentials at aws.amazon.com
8-
secret: getEnv('APOS_S3_SECRET'),
9-
key: getEnv('APOS_S3_KEY'),
10-
// Bucket name created on aws.amazon.com
11-
bucket: getEnv('APOS_S3_BUCKET'),
12-
// Region name for endpoint
13-
region: getEnv('APOS_S3_REGION'),
14-
endpoint: getEnv('APOS_S3_ENDPOINT'),
15-
style: getEnv('APOS_S3_STYLE'),
16-
https: getEnv('APOS_S3_HTTPS'),
17-
cdn: {
18-
enabled: true,
19-
url: getEnv('APOS_CDN_URL'),
20-
},
21-
},
26+
uploadfs: uploadfsOptions,
2227
},
2328
};
2429

0 commit comments

Comments
 (0)