Skip to content

Commit 49170c8

Browse files
authored
Merge pull request #12 from citymapper/allow_env_credentials
Use default credential chain if credentialsfile not specified
2 parents 3e226f5 + 49d8690 commit 49170c8

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

main.go

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ func isValidConfig(config Configs) bool {
7272
valid = valid && config.WebConfigs.Port > 0
7373
valid = valid && config.WebConfigs.Port < 65535
7474
valid = valid && len(config.S3configs.BucketName) > 0
75-
valid = valid && len(config.S3configs.CredentialsFile) > 0
7675
valid = valid && len(config.S3configs.Region) > 0
7776
return valid
7877
}

s3fetcher.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

33
import (
4+
"log"
5+
46
"github.com/aws/aws-sdk-go/aws"
57
"github.com/aws/aws-sdk-go/aws/credentials"
68
"github.com/aws/aws-sdk-go/aws/session"
@@ -20,9 +22,15 @@ type S3configs struct {
2022
// NewS3Fetcher is a S3 backed implementation of the FileFetcher interface.
2123
// it does the setup of the S3 service session state required to implement FileFetcher interface
2224
func NewS3Fetcher(cfg S3configs) FileFetcher {
23-
svc := s3.New(session.New(
24-
aws.NewConfig().WithRegion(cfg.Region).WithCredentials(
25-
credentials.NewSharedCredentials(cfg.CredentialsFile, "default"))))
25+
awsCfg := aws.NewConfig().WithRegion(cfg.Region)
26+
if cfg.CredentialsFile != "" {
27+
log.Printf("using AWS credentials from %s", cfg.CredentialsFile)
28+
awsCfg = awsCfg.WithCredentials(credentials.NewSharedCredentials(cfg.CredentialsFile, "default"))
29+
} else {
30+
log.Print("no AWS credentials file specified, using the default credentials chain")
31+
}
32+
33+
svc := s3.New(session.New(awsCfg))
2634
cfg.s3svc = svc
2735

2836
return cfg

0 commit comments

Comments
 (0)