Skip to content

Commit

Permalink
Merge pull request #3181 from pimuzzo/s3-transfer-accelerate
Browse files Browse the repository at this point in the history
Add new parameter accelerate to S3 storage driver.
  • Loading branch information
milosgajdos committed Apr 4, 2022
2 parents dc7f44b + 80952c9 commit cd51f38
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ storage:
secretkey: awssecretkey
region: us-west-1
regionendpoint: http://myobjects.local
accelerate: false
bucket: bucketname
encrypt: true
keyid: mykeyid
Expand Down Expand Up @@ -422,6 +423,7 @@ storage:
secretkey: awssecretkey
region: us-west-1
regionendpoint: http://myobjects.local
accelerate: false
bucket: bucketname
encrypt: true
keyid: mykeyid
Expand Down
20 changes: 20 additions & 0 deletions registry/storage/driver/s3-aws/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ type DriverParameters struct {
ObjectACL string
SessionToken string
UseDualStack bool
Accelerate bool
}

func init() {
Expand Down Expand Up @@ -377,6 +378,23 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {

sessionToken := ""

accelerateBool := false
accelerate := parameters["accelerate"]
switch accelerate := accelerate.(type) {
case string:
b, err := strconv.ParseBool(accelerate)
if err != nil {
return nil, fmt.Errorf("the accelerate parameter should be a boolean")
}
accelerateBool = b
case bool:
accelerateBool = accelerate
case nil:
// do nothing
default:
return nil, fmt.Errorf("the accelerate parameter should be a boolean")
}

params := DriverParameters{
fmt.Sprint(accessKey),
fmt.Sprint(secretKey),
Expand All @@ -399,6 +417,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
objectACL,
fmt.Sprint(sessionToken),
useDualStackBool,
accelerateBool,
}

return New(params)
Expand Down Expand Up @@ -458,6 +477,7 @@ func New(params DriverParameters) (*Driver, error) {
awsConfig.WithEndpoint(params.RegionEndpoint)
}

awsConfig.WithS3UseAccelerate(params.Accelerate)
awsConfig.WithRegion(params.Region)
awsConfig.WithDisableSSL(!params.Secure)
if params.UseDualStack {
Expand Down
11 changes: 11 additions & 0 deletions registry/storage/driver/s3-aws/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func init() {
sessionToken := os.Getenv("AWS_SESSION_TOKEN")
useDualStack := os.Getenv("S3_USE_DUALSTACK")
combineSmallPart := os.Getenv("MULTIPART_COMBINE_SMALL_PART")
accelerate := os.Getenv("S3_ACCELERATE")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -86,6 +87,7 @@ func init() {
if useDualStack != "" {
useDualStackBool, err = strconv.ParseBool(useDualStack)
}

multipartCombineSmallPart := true
if combineSmallPart != "" {
multipartCombineSmallPart, err = strconv.ParseBool(combineSmallPart)
Expand All @@ -94,6 +96,14 @@ func init() {
}
}

accelerateBool := true
if accelerate != "" {
accelerateBool, err = strconv.ParseBool(accelerate)
if err != nil {
return nil, err
}
}

parameters := DriverParameters{
accessKey,
secretKey,
Expand All @@ -116,6 +126,7 @@ func init() {
objectACL,
sessionToken,
useDualStackBool,
accelerateBool,
}

return New(parameters)
Expand Down

0 comments on commit cd51f38

Please sign in to comment.