Skip to content

Commit

Permalink
blob/s3blob: Allow using s3ForcePathStyle as a synonym of use_path_st…
Browse files Browse the repository at this point in the history
…yle, for backwards compatibility with V1
  • Loading branch information
vangent committed Nov 7, 2024
1 parent e9bda0a commit 742f884
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
34 changes: 21 additions & 13 deletions blob/s3blob/s3blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions blob/s3blob/s3blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 742f884

Please sign in to comment.