Skip to content

Commit 282e551

Browse files
authored
Merge pull request #143 from tecc/widdix-aws-iam-roles
See #95 and #128. Original code is from @andreaswittig.
2 parents 31682cc + 9c4c9ab commit 282e551

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

Diff for: libs/server/config.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ export type BasicAuthConfiguration = { type: 'basic' } & (
1818
export type AuthConfiguration = { type: 'none' } | BasicAuthConfiguration;
1919

2020
export interface S3StoreConfiguration {
21-
accessKey: string;
22-
secretKey: string;
21+
detectCredentials: boolean;
22+
accessKey?: string;
23+
secretKey?: string;
2324
bucket: string;
2425
endpoint: string;
2526
region: string;
@@ -96,16 +97,17 @@ export function loadConfig() {
9697
}
9798
// for now, this works
9899
{
100+
store.detectCredentials ??= true;
99101
store.accessKey = getEnv<string>(
100102
'STORE_ACCESS_KEY',
101103
store.accessKey,
102-
!store.accessKey
103-
).toString();
104+
!store.detectCredentials
105+
)?.toString();
104106
store.secretKey = getEnv<string>(
105107
'STORE_SECRET_KEY',
106108
store.secretKey,
107-
!store.secretKey
108-
).toString();
109+
!store.detectCredentials
110+
)?.toString();
109111
store.bucket = getEnv<string>(
110112
'STORE_BUCKET',
111113
store.bucket ?? 'notea',

Diff for: libs/server/store/providers/s3.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ export class StoreS3 extends StoreProvider {
4040
forcePathStyle: config.pathStyle,
4141
region: config.region,
4242
endpoint: config.endPoint,
43-
credentials: {
43+
credentials: ((config.accessKey && config.secretKey) ? {
4444
accessKeyId: config.accessKey,
4545
secretAccessKey: config.secretKey,
46-
},
46+
} : undefined),
4747
});
48+
if (!config.accessKey || !config.secretKey) {
49+
console.log('[Notea] Environment variables STORE_ACCESS_KEY or STORE_SECRET_KEY is missing. Trying to use IAM role credentials instead ...');
50+
}
4851
this.config = config;
4952
}
5053

0 commit comments

Comments
 (0)