From 56954848c3aac17e97ce719cfa55fb09ed4e8ddf Mon Sep 17 00:00:00 2001 From: Robert van Gent Date: Thu, 7 Nov 2024 10:50:25 -0800 Subject: [PATCH] blob/s3blob: Allow using s3ForcePathStyle as a synonym of use_path_style, for backwards compatibility with V1 (#3505) --- blob/s3blob/s3blob.go | 34 +++++++++++++++++++++------------- blob/s3blob/s3blob_test.go | 2 ++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/blob/s3blob/s3blob.go b/blob/s3blob/s3blob.go index f575649b7e..f0ff6f099f 100644 --- a/blob/s3blob/s3blob.go +++ b/blob/s3blob/s3blob.go @@ -135,6 +135,11 @@ const Scheme = "s3" // - kmskeyid: The KMS key ID for server side encryption // - accelerate: A value of "true" uses the S3 Transfer Accleration endpoints // +// V2 additionally supports: +// - use_path_style: A value of true sets the UsePathStyle option. +// - s3ForcePathStyle: Same as use_path_style, for backwards compatibility with V1. +// - disable_https: A value of true disables HTTPS in the Endpoint options. +// // For V1, see gocloud.dev/aws/ConfigFromURLParams for supported query parameters // for overriding the aws.Session from the URL. // For V2, see gocloud.dev/aws/V2ConfigFromURLParams. @@ -150,11 +155,12 @@ type URLOpener struct { } const ( - sseTypeParamKey = "ssetype" - kmsKeyIdParamKey = "kmskeyid" - accelerateParamKey = "accelerate" - usePathStyleParamkey = "use_path_style" - disableHTTPSParamKey = "disable_https" + sseTypeParamKey = "ssetype" + kmsKeyIdParamKey = "kmskeyid" + accelerateParamKey = "accelerate" + usePathStyleParamKey = "use_path_style" + legacyUsePathStyleParamKey = "s3ForcePathStyle" // for backwards compatibility + disableHTTPSParamKey = "disable_https" ) func toServerSideEncryptionType(value string) (typesv2.ServerSideEncryption, error) { @@ -212,15 +218,17 @@ func (o *URLOpener) OpenBucketURL(ctx context.Context, u *url.URL) (*blob.Bucket o.EndpointOptions.DisableHTTPS = value }) } - if usePathStyleParam := q.Get(usePathStyleParamkey); usePathStyleParam != "" { - q.Del(usePathStyleParamkey) - value, err := strconv.ParseBool(usePathStyleParam) - if err != nil { - return nil, fmt.Errorf("invalid value for %q: %v", usePathStyleParamkey, err) + for _, key := range []string{usePathStyleParamKey, legacyUsePathStyleParamKey} { + if usePathStyleParam := q.Get(key); usePathStyleParam != "" { + q.Del(key) + value, err := strconv.ParseBool(usePathStyleParam) + if err != nil { + return nil, fmt.Errorf("invalid value for %q: %v", key, err) + } + opts = append(opts, func(o *s3v2.Options) { + o.UsePathStyle = value + }) } - opts = append(opts, func(o *s3v2.Options) { - o.UsePathStyle = value - }) } cfg, err := gcaws.V2ConfigFromURLParams(ctx, q) diff --git a/blob/s3blob/s3blob_test.go b/blob/s3blob/s3blob_test.go index 2639b74d70..508964ab25 100644 --- a/blob/s3blob/s3blob_test.go +++ b/blob/s3blob/s3blob_test.go @@ -484,6 +484,8 @@ func TestOpenBucketFromURL(t *testing.T) { {"s3://mybucket?awssdk=v1&accelerate=true&dualstack=true", false}, // OK, use use_path_style {"s3://mybucket?use_path_style=true", false}, + // OK, use s3ForcePathStyle + {"s3://mybucket?s3ForcePathStyle=true", false}, // OK, use disable_https {"s3://mybucket?disable_https=true", false}, // OK, use FIPS endpoints (v1)