Skip to content

Commit

Permalink
s3: enable shared config state
Browse files Browse the repository at this point in the history
  • Loading branch information
enescakir authored and drakkan committed Feb 16, 2020
1 parent 0b7be11 commit da01848
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
27 changes: 19 additions & 8 deletions vfs/s3fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,31 @@ func NewS3Fs(connectionID, localTempDir string, config S3FsConfig) (Fs, error) {
if err := ValidateS3FsConfig(&fs.config); err != nil {
return fs, err
}
accessSecret, err := utils.DecryptData(fs.config.AccessSecret)
if err != nil {
return fs, err
awsConfig := aws.NewConfig()

if len(fs.config.Region) > 0 {
awsConfig.WithRegion(fs.config.Region)
}
fs.config.AccessSecret = accessSecret
awsConfig := &aws.Config{
Region: aws.String(fs.config.Region),
Credentials: credentials.NewStaticCredentials(fs.config.AccessKey, fs.config.AccessSecret, ""),

if len(fs.config.AccessSecret) > 0 {
accessSecret, err := utils.DecryptData(fs.config.AccessSecret)
if err != nil {
return fs, err
}
fs.config.AccessSecret = accessSecret
awsConfig.Credentials = credentials.NewStaticCredentials(fs.config.AccessKey, fs.config.AccessSecret, "")
}

if len(fs.config.Endpoint) > 0 {
awsConfig.Endpoint = aws.String(fs.config.Endpoint)
awsConfig.S3ForcePathStyle = aws.Bool(true)
}
sess, err := session.NewSession(awsConfig)

sessOpts := session.Options{
Config: *awsConfig,
SharedConfigState: session.SharedConfigEnable,
}
sess, err := session.NewSessionWithOptions(sessOpts)
if err != nil {
return fs, err
}
Expand Down
6 changes: 0 additions & 6 deletions vfs/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ func ValidateS3FsConfig(config *S3FsConfig) error {
if len(config.Region) == 0 {
return errors.New("region cannot be empty")
}
if len(config.AccessKey) == 0 {
return errors.New("access_key cannot be empty")
}
if len(config.AccessSecret) == 0 {
return errors.New("access_secret cannot be empty")
}
if len(config.KeyPrefix) > 0 {
if strings.HasPrefix(config.KeyPrefix, "/") {
return errors.New("key_prefix cannot start with /")
Expand Down

0 comments on commit da01848

Please sign in to comment.