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 <kirat.singh@wsq.io>
Signed-off-by: Simone Locci <simonelocci88@gmail.com>
This commit is contained in:
Kirat Singh 2017-01-20 12:12:37 -05:00 committed by Simone Locci
parent dc7f44b613
commit 51c0c8148a
No known key found for this signature in database
GPG key ID: EA8A965E9EA17D84
3 changed files with 36 additions and 0 deletions

View file

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

View file

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

View file

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