Skip to content

Commit af4c9dd

Browse files
authored
blob/s3blob: Add disable_https and use_path_style query param options
1 parent bbdd0b3 commit af4c9dd

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

blob/s3blob/s3blob.go

+32-6
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ type URLOpener struct {
150150
}
151151

152152
const (
153-
sseTypeParamKey = "ssetype"
154-
kmsKeyIdParamKey = "kmskeyid"
155-
accelerateParamKey = "accelerate"
153+
sseTypeParamKey = "ssetype"
154+
kmsKeyIdParamKey = "kmskeyid"
155+
accelerateParamKey = "accelerate"
156+
usePathStyleParamkey = "use_path_style"
157+
disableHTTPSParamKey = "disable_https"
156158
)
157159

158160
func toServerSideEncryptionType(value string) (typesv2.ServerSideEncryption, error) {
@@ -195,13 +197,37 @@ func (o *URLOpener) OpenBucketURL(ctx context.Context, u *url.URL) (*blob.Bucket
195197
}
196198

197199
if o.UseV2 {
200+
opts := []func(*s3v2.Options){
201+
func(o *s3v2.Options) {
202+
o.UseAccelerate = accelerate
203+
},
204+
}
205+
if disableHTTPSParam := q.Get(disableHTTPSParamKey); disableHTTPSParam != "" {
206+
q.Del(disableHTTPSParamKey)
207+
value, err := strconv.ParseBool(disableHTTPSParam)
208+
if err != nil {
209+
return nil, fmt.Errorf("invalid value for %q: %v", disableHTTPSParamKey, err)
210+
}
211+
opts = append(opts, func(o *s3v2.Options) {
212+
o.EndpointOptions.DisableHTTPS = value
213+
})
214+
}
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)
220+
}
221+
opts = append(opts, func(o *s3v2.Options) {
222+
o.UsePathStyle = value
223+
})
224+
}
225+
198226
cfg, err := gcaws.V2ConfigFromURLParams(ctx, q)
199227
if err != nil {
200228
return nil, fmt.Errorf("open bucket %v: %v", u, err)
201229
}
202-
clientV2 := s3v2.NewFromConfig(cfg, func(o *s3v2.Options) {
203-
o.UseAccelerate = accelerate
204-
})
230+
clientV2 := s3v2.NewFromConfig(cfg, opts...)
205231

206232
return OpenBucketV2(ctx, clientV2, u.Host, &o.Options)
207233
}

blob/s3blob/s3blob_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,10 @@ func TestOpenBucketFromURL(t *testing.T) {
482482
{"s3://mybucket?fips=true", false},
483483
// OK, use S3 Transfer accleration and dual stack endpoints (v1)
484484
{"s3://mybucket?awssdk=v1&accelerate=true&dualstack=true", false},
485+
// OK, use use_path_style
486+
{"s3://mybucket?use_path_style=true", false},
487+
// OK, use disable_https
488+
{"s3://mybucket?disable_https=true", false},
485489
// OK, use FIPS endpoints (v1)
486490
{"s3://mybucket?awssdk=v1&fips=true", false},
487491
// Invalid accelerate (v1)
@@ -500,6 +504,10 @@ func TestOpenBucketFromURL(t *testing.T) {
500504
{"s3://mybucket?ssetype=aws:notkmsoraes&kmskeyid=arn:aws:us-east-1:12345:key/1-a-2-b", true},
501505
// Invalid parameter together with a valid one.
502506
{"s3://mybucket?profile=main&param=value", true},
507+
// Invalid use_path_style (v1)
508+
{"s3://mybucket?awssdk=v1&usePathStyle=bad", true},
509+
// Invalid disable_https (v2)
510+
{"s3://mybucket?usePathStyle=bad", true},
503511
// Invalid parameter.
504512
{"s3://mybucket?param=value", true},
505513
}

0 commit comments

Comments
 (0)