Skip to content

Commit 742f884

Browse files
committed
blob/s3blob: Allow using s3ForcePathStyle as a synonym of use_path_style, for backwards compatibility with V1
1 parent e9bda0a commit 742f884

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

blob/s3blob/s3blob.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ const Scheme = "s3"
135135
// - kmskeyid: The KMS key ID for server side encryption
136136
// - accelerate: A value of "true" uses the S3 Transfer Accleration endpoints
137137
//
138+
// V2 additionally supports:
139+
// - use_path_style: A value of true sets the UsePathStyle option.
140+
// - s3ForcePathStyle: Same as use_path_style, for backwards compatibility with V1.
141+
// - disable_https: A value of true disables HTTPS in the Endpoint options.
142+
//
138143
// For V1, see gocloud.dev/aws/ConfigFromURLParams for supported query parameters
139144
// for overriding the aws.Session from the URL.
140145
// For V2, see gocloud.dev/aws/V2ConfigFromURLParams.
@@ -150,11 +155,12 @@ type URLOpener struct {
150155
}
151156

152157
const (
153-
sseTypeParamKey = "ssetype"
154-
kmsKeyIdParamKey = "kmskeyid"
155-
accelerateParamKey = "accelerate"
156-
usePathStyleParamkey = "use_path_style"
157-
disableHTTPSParamKey = "disable_https"
158+
sseTypeParamKey = "ssetype"
159+
kmsKeyIdParamKey = "kmskeyid"
160+
accelerateParamKey = "accelerate"
161+
usePathStyleParamKey = "use_path_style"
162+
legacyUsePathStyleParamKey = "s3ForcePathStyle" // for backwards compatibility
163+
disableHTTPSParamKey = "disable_https"
158164
)
159165

160166
func toServerSideEncryptionType(value string) (typesv2.ServerSideEncryption, error) {
@@ -212,15 +218,17 @@ func (o *URLOpener) OpenBucketURL(ctx context.Context, u *url.URL) (*blob.Bucket
212218
o.EndpointOptions.DisableHTTPS = value
213219
})
214220
}
215-
if usePathStyleParam := q.Get(usePathStyleParamkey); usePathStyleParam != "" {
216-
q.Del(usePathStyleParamkey)
217-
value, err := strconv.ParseBool(usePathStyleParam)
218-
if err != nil {
219-
return nil, fmt.Errorf("invalid value for %q: %v", usePathStyleParamkey, err)
221+
for _, key := range []string{usePathStyleParamKey, legacyUsePathStyleParamKey} {
222+
if usePathStyleParam := q.Get(key); usePathStyleParam != "" {
223+
q.Del(key)
224+
value, err := strconv.ParseBool(usePathStyleParam)
225+
if err != nil {
226+
return nil, fmt.Errorf("invalid value for %q: %v", key, err)
227+
}
228+
opts = append(opts, func(o *s3v2.Options) {
229+
o.UsePathStyle = value
230+
})
220231
}
221-
opts = append(opts, func(o *s3v2.Options) {
222-
o.UsePathStyle = value
223-
})
224232
}
225233

226234
cfg, err := gcaws.V2ConfigFromURLParams(ctx, q)

blob/s3blob/s3blob_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ func TestOpenBucketFromURL(t *testing.T) {
484484
{"s3://mybucket?awssdk=v1&accelerate=true&dualstack=true", false},
485485
// OK, use use_path_style
486486
{"s3://mybucket?use_path_style=true", false},
487+
// OK, use s3ForcePathStyle
488+
{"s3://mybucket?s3ForcePathStyle=true", false},
487489
// OK, use disable_https
488490
{"s3://mybucket?disable_https=true", false},
489491
// OK, use FIPS endpoints (v1)

0 commit comments

Comments
 (0)