diff --git a/docs/configuration.md b/docs/configuration.md index b2f09a21..6cc2c02b 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -128,6 +128,7 @@ storage: multipartcopymaxconcurrency: 100 multipartcopythresholdsize: 33554432 rootdirectory: /s3/object/name/prefix + usedualstack: false swift: username: username password: password diff --git a/registry/storage/driver/s3-aws/s3.go b/registry/storage/driver/s3-aws/s3.go index 75f80b7e..b9388ff4 100644 --- a/registry/storage/driver/s3-aws/s3.go +++ b/registry/storage/driver/s3-aws/s3.go @@ -102,6 +102,7 @@ type DriverParameters struct { UserAgent string ObjectACL string SessionToken string + UseDualStack bool } func init() { @@ -338,6 +339,23 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { objectACL = objectACLString } + useDualStackBool := false + useDualStack := parameters["usedualstack"] + switch useDualStack := useDualStack.(type) { + case string: + b, err := strconv.ParseBool(useDualStack) + if err != nil { + return nil, fmt.Errorf("the useDualStack parameter should be a boolean") + } + useDualStackBool = b + case bool: + useDualStackBool = useDualStack + case nil: + // do nothing + default: + return nil, fmt.Errorf("the useDualStack parameter should be a boolean") + } + sessionToken := "" params := DriverParameters{ @@ -360,6 +378,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { fmt.Sprint(userAgent), objectACL, fmt.Sprint(sessionToken), + useDualStackBool, } return New(params) @@ -421,6 +440,9 @@ func New(params DriverParameters) (*Driver, error) { awsConfig.WithRegion(params.Region) awsConfig.WithDisableSSL(!params.Secure) + if params.UseDualStack { + awsConfig.UseDualStackEndpoint = endpoints.DualStackEndpointStateEnabled + } if params.UserAgent != "" || params.SkipVerify { httpTransport := http.DefaultTransport diff --git a/registry/storage/driver/s3-aws/s3_test.go b/registry/storage/driver/s3-aws/s3_test.go index 325e2e28..4d4631a7 100644 --- a/registry/storage/driver/s3-aws/s3_test.go +++ b/registry/storage/driver/s3-aws/s3_test.go @@ -42,6 +42,7 @@ func init() { root, err := ioutil.TempDir("", "driver-") regionEndpoint := os.Getenv("REGION_ENDPOINT") sessionToken := os.Getenv("AWS_SESSION_TOKEN") + useDualStack := os.Getenv("S3_USE_DUALSTACK") if err != nil { panic(err) } @@ -80,6 +81,14 @@ func init() { } } + useDualStackBool := false + if useDualStack != "" { + useDualStackBool, err = strconv.ParseBool(useDualStack) + if err != nil { + return nil, err + } + } + parameters := DriverParameters{ accessKey, secretKey, @@ -100,6 +109,7 @@ func init() { driverName + "-test", objectACL, sessionToken, + useDualStackBool, } return New(parameters)