From 51c0c8148ab75fae72f60957b3b9f246e421b6f5 Mon Sep 17 00:00:00 2001 From: Kirat Singh Date: Fri, 20 Jan 2017 12:12:37 -0500 Subject: [PATCH 1/3] Add new parameter s3accelerate to S3 storage driver. If s3accelerate is set to true then we turn on S3 Transfer Acceleration via the AWS SDK. It defaults to false since this is an opt-in feature on the S3 bucket. Signed-off-by: Kirat Singh Signed-off-by: Simone Locci --- docs/configuration.md | 2 ++ registry/storage/driver/s3-aws/s3.go | 23 +++++++++++++++++++++++ registry/storage/driver/s3-aws/s3_test.go | 11 +++++++++++ 3 files changed, 36 insertions(+) diff --git a/docs/configuration.md b/docs/configuration.md index 603181950..037d2912b 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -118,6 +118,7 @@ storage: secretkey: awssecretkey region: us-west-1 regionendpoint: http://myobjects.local + s3accelerate: false bucket: bucketname encrypt: true keyid: mykeyid @@ -422,6 +423,7 @@ storage: secretkey: awssecretkey region: us-west-1 regionendpoint: http://myobjects.local + s3accelerate: false bucket: bucketname encrypt: true keyid: mykeyid diff --git a/registry/storage/driver/s3-aws/s3.go b/registry/storage/driver/s3-aws/s3.go index 238c5d80a..3b1c9eb53 100644 --- a/registry/storage/driver/s3-aws/s3.go +++ b/registry/storage/driver/s3-aws/s3.go @@ -104,6 +104,7 @@ type DriverParameters struct { ObjectACL string SessionToken string UseDualStack bool + S3Accelerate bool } func init() { @@ -377,6 +378,23 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { sessionToken := "" + s3accelerateBool := false + s3accelerate := parameters["s3accelerate"] + switch s3accelerate := s3accelerate.(type) { + case string: + b, err := strconv.ParseBool(s3accelerate) + if err != nil { + return nil, fmt.Errorf("The s3accelerate parameter should be a boolean") + } + s3accelerateBool = b + case bool: + s3accelerateBool = s3accelerate + case nil: + // do nothing + default: + return nil, fmt.Errorf("The s3accelerate parameter should be a boolean") + } + params := DriverParameters{ fmt.Sprint(accessKey), fmt.Sprint(secretKey), @@ -399,6 +417,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { objectACL, fmt.Sprint(sessionToken), useDualStackBool, + s3accelerateBool, } return New(params) @@ -458,6 +477,10 @@ func New(params DriverParameters) (*Driver, error) { awsConfig.WithEndpoint(params.RegionEndpoint) } + if params.S3Accelerate { + awsConfig.WithS3UseAccelerate(true) + } + awsConfig.WithRegion(params.Region) awsConfig.WithDisableSSL(!params.Secure) if params.UseDualStack { diff --git a/registry/storage/driver/s3-aws/s3_test.go b/registry/storage/driver/s3-aws/s3_test.go index 31662b175..0314eaaf6 100644 --- a/registry/storage/driver/s3-aws/s3_test.go +++ b/registry/storage/driver/s3-aws/s3_test.go @@ -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") + s3accelerate := os.Getenv("S3_ACCELERATE") if err != nil { panic(err) } @@ -86,6 +87,7 @@ func init() { if useDualStack != "" { useDualStackBool, err = strconv.ParseBool(useDualStack) } + multipartCombineSmallPart := true if combineSmallPart != "" { multipartCombineSmallPart, err = strconv.ParseBool(combineSmallPart) @@ -94,6 +96,14 @@ func init() { } } + s3accelerateBool := true + if s3accelerate != "" { + s3accelerateBool, err = strconv.ParseBool(s3accelerate) + if err != nil { + return nil, err + } + } + parameters := DriverParameters{ accessKey, secretKey, @@ -116,6 +126,7 @@ func init() { objectACL, sessionToken, useDualStackBool, + s3accelerateBool, } return New(parameters) From ea27621d4a2d9c0d0122d23004ef317077783298 Mon Sep 17 00:00:00 2001 From: Simone Locci Date: Tue, 14 Jul 2020 09:46:14 +0200 Subject: [PATCH 2/3] Fix review Signed-off-by: Simone Locci --- registry/storage/driver/s3-aws/s3.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/registry/storage/driver/s3-aws/s3.go b/registry/storage/driver/s3-aws/s3.go index 3b1c9eb53..fe31d390e 100644 --- a/registry/storage/driver/s3-aws/s3.go +++ b/registry/storage/driver/s3-aws/s3.go @@ -477,10 +477,7 @@ func New(params DriverParameters) (*Driver, error) { awsConfig.WithEndpoint(params.RegionEndpoint) } - if params.S3Accelerate { - awsConfig.WithS3UseAccelerate(true) - } - + awsConfig.WithS3UseAccelerate(params.S3Accelerate) awsConfig.WithRegion(params.Region) awsConfig.WithDisableSSL(!params.Secure) if params.UseDualStack { From 80952c9e2b75e1bc80fa138f9354d000d6a56b59 Mon Sep 17 00:00:00 2001 From: Simone Locci Date: Sun, 21 Feb 2021 15:44:19 +0100 Subject: [PATCH 3/3] Rename s3accelerate parameter to accelerate Signed-off-by: Simone Locci --- docs/configuration.md | 4 ++-- registry/storage/driver/s3-aws/s3.go | 22 +++++++++++----------- registry/storage/driver/s3-aws/s3_test.go | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 037d2912b..8cd72cae3 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -118,7 +118,7 @@ storage: secretkey: awssecretkey region: us-west-1 regionendpoint: http://myobjects.local - s3accelerate: false + accelerate: false bucket: bucketname encrypt: true keyid: mykeyid @@ -423,7 +423,7 @@ storage: secretkey: awssecretkey region: us-west-1 regionendpoint: http://myobjects.local - s3accelerate: false + accelerate: false bucket: bucketname encrypt: true keyid: mykeyid diff --git a/registry/storage/driver/s3-aws/s3.go b/registry/storage/driver/s3-aws/s3.go index fe31d390e..ba76f4248 100644 --- a/registry/storage/driver/s3-aws/s3.go +++ b/registry/storage/driver/s3-aws/s3.go @@ -104,7 +104,7 @@ type DriverParameters struct { ObjectACL string SessionToken string UseDualStack bool - S3Accelerate bool + Accelerate bool } func init() { @@ -378,21 +378,21 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { sessionToken := "" - s3accelerateBool := false - s3accelerate := parameters["s3accelerate"] - switch s3accelerate := s3accelerate.(type) { + accelerateBool := false + accelerate := parameters["accelerate"] + switch accelerate := accelerate.(type) { case string: - b, err := strconv.ParseBool(s3accelerate) + b, err := strconv.ParseBool(accelerate) if err != nil { - return nil, fmt.Errorf("The s3accelerate parameter should be a boolean") + return nil, fmt.Errorf("the accelerate parameter should be a boolean") } - s3accelerateBool = b + accelerateBool = b case bool: - s3accelerateBool = s3accelerate + accelerateBool = accelerate case nil: // do nothing default: - return nil, fmt.Errorf("The s3accelerate parameter should be a boolean") + return nil, fmt.Errorf("the accelerate parameter should be a boolean") } params := DriverParameters{ @@ -417,7 +417,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { objectACL, fmt.Sprint(sessionToken), useDualStackBool, - s3accelerateBool, + accelerateBool, } return New(params) @@ -477,7 +477,7 @@ func New(params DriverParameters) (*Driver, error) { awsConfig.WithEndpoint(params.RegionEndpoint) } - awsConfig.WithS3UseAccelerate(params.S3Accelerate) + awsConfig.WithS3UseAccelerate(params.Accelerate) awsConfig.WithRegion(params.Region) awsConfig.WithDisableSSL(!params.Secure) if params.UseDualStack { diff --git a/registry/storage/driver/s3-aws/s3_test.go b/registry/storage/driver/s3-aws/s3_test.go index 0314eaaf6..41a5fc7da 100644 --- a/registry/storage/driver/s3-aws/s3_test.go +++ b/registry/storage/driver/s3-aws/s3_test.go @@ -44,7 +44,7 @@ func init() { sessionToken := os.Getenv("AWS_SESSION_TOKEN") useDualStack := os.Getenv("S3_USE_DUALSTACK") combineSmallPart := os.Getenv("MULTIPART_COMBINE_SMALL_PART") - s3accelerate := os.Getenv("S3_ACCELERATE") + accelerate := os.Getenv("S3_ACCELERATE") if err != nil { panic(err) } @@ -96,9 +96,9 @@ func init() { } } - s3accelerateBool := true - if s3accelerate != "" { - s3accelerateBool, err = strconv.ParseBool(s3accelerate) + accelerateBool := true + if accelerate != "" { + accelerateBool, err = strconv.ParseBool(accelerate) if err != nil { return nil, err } @@ -126,7 +126,7 @@ func init() { objectACL, sessionToken, useDualStackBool, - s3accelerateBool, + accelerateBool, } return New(parameters)