@@ -8,32 +8,33 @@ import requiredParameter from '../../requiredParameter';
8
8
9
9
const DEFAULT_S3_REGION = "us-east-1" ;
10
10
11
- function parseS3AdapterOptions ( ...options ) {
12
- if ( options . length === 1 && typeof options [ 0 ] == "object" ) {
13
- return options ;
11
+ function requiredOrFromEnvironment ( env , name ) {
12
+ let environmentVariable = process . env [ env ] ;
13
+ if ( ! environmentVariable ) {
14
+ requiredParameter ( `S3Adapter requires an ${ name } ` ) ;
14
15
}
15
-
16
- const additionalOptions = options [ 3 ] || { } ;
17
-
18
- return {
19
- accessKey : options [ 0 ] ,
20
- secretKey : options [ 1 ] ,
21
- bucket : options [ 2 ] ,
22
- region : additionalOptions . region
16
+ return environmentVariable ;
17
+ }
18
+
19
+ function fromEnvironmentOrDefault ( env , defaultValue ) {
20
+ let environmentVariable = process . env [ env ] ;
21
+ if ( environmentVariable ) {
22
+ return environmentVariable ;
23
23
}
24
+ return defaultValue ;
24
25
}
25
26
26
27
export class S3Adapter extends FilesAdapter {
27
28
// Creates an S3 session.
28
29
// Providing AWS access and secret keys is mandatory
29
30
// Region and bucket will use sane defaults if omitted
30
31
constructor (
31
- accessKey = requiredParameter ( 'S3Adapter requires an accessKey') ,
32
- secretKey = requiredParameter ( 'S3Adapter requires a secretKey') ,
33
- bucket ,
34
- { region = DEFAULT_S3_REGION ,
35
- bucketPrefix = '' ,
36
- directAccess = false } = { } ) {
32
+ accessKey = requiredOrFromEnvironment ( 'S3_ACCESS_KEY' , ' accessKey') ,
33
+ secretKey = requiredOrFromEnvironment ( 'S3_SECRET_KEY' , ' secretKey') ,
34
+ bucket = fromEnvironmentOrDefault ( 'S3_BUCKET' , undefined ) ,
35
+ { region = fromEnvironmentOrDefault ( 'S3_REGION' , DEFAULT_S3_REGION ) ,
36
+ bucketPrefix = fromEnvironmentOrDefault ( 'S3_BUCKET_PREFIX' , '' ) ,
37
+ directAccess = fromEnvironmentOrDefault ( 'S3_DIRECT_ACCESS' , false ) } = { } ) {
37
38
super ( ) ;
38
39
39
40
this . _region = region ;
0 commit comments