s3: enable shared config state

This commit is contained in:
Enes Çakır 2020-02-16 00:06:19 +03:00 committed by drakkan
parent 0b7be1175d
commit da01848855
2 changed files with 19 additions and 14 deletions

View file

@ -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
}

View file

@ -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 /")