Skip to content

Commit

Permalink
Merge pull request #12 from citymapper/allow_env_credentials
Browse files Browse the repository at this point in the history
Use default credential chain if credentialsfile not specified
  • Loading branch information
slai authored Jan 2, 2019
2 parents 3e226f5 + 49d8690 commit 49170c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func isValidConfig(config Configs) bool {
valid = valid && config.WebConfigs.Port > 0
valid = valid && config.WebConfigs.Port < 65535
valid = valid && len(config.S3configs.BucketName) > 0
valid = valid && len(config.S3configs.CredentialsFile) > 0
valid = valid && len(config.S3configs.Region) > 0
return valid
}
14 changes: 11 additions & 3 deletions s3fetcher.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
Expand All @@ -20,9 +22,15 @@ type S3configs struct {
// NewS3Fetcher is a S3 backed implementation of the FileFetcher interface.
// it does the setup of the S3 service session state required to implement FileFetcher interface
func NewS3Fetcher(cfg S3configs) FileFetcher {
svc := s3.New(session.New(
aws.NewConfig().WithRegion(cfg.Region).WithCredentials(
credentials.NewSharedCredentials(cfg.CredentialsFile, "default"))))
awsCfg := aws.NewConfig().WithRegion(cfg.Region)
if cfg.CredentialsFile != "" {
log.Printf("using AWS credentials from %s", cfg.CredentialsFile)
awsCfg = awsCfg.WithCredentials(credentials.NewSharedCredentials(cfg.CredentialsFile, "default"))
} else {
log.Print("no AWS credentials file specified, using the default credentials chain")
}

svc := s3.New(session.New(awsCfg))
cfg.s3svc = svc

return cfg
Expand Down

0 comments on commit 49170c8

Please sign in to comment.