Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use default credential chain if credentialsfile not specified #12

Merged
merged 1 commit into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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