Skip to content

Commit 1e05599

Browse files
cgrardfrezbo
authored andcommitted
feat: add support for UsePathStyle in ServiceConfig
This commit adds the `UsePathStyle` field to the `ServiceConfig` struct in `pkg/config/service.go`. The `UsePathStyle` parameter is optional and allows users to specify whether to use path-style URLs for S3 requests. The value of `UsePathStyle` is read from the `USE_PATH_STYLE` environment variable and defaults to `false`. Refactor the `CreateClientWithCustomEndpoint` function in `pkg/s3/s3.go` to set the `UsePathStyle` option based on the value of `svcConf.UsePathStyle`. This ensures that the S3 client uses path-style URLs when the `UsePathStyle` parameter is enabled. Signed-off-by: Cedric Grard <[email protected]> Signed-off-by: Noel Georgi <[email protected]>
1 parent ec893b4 commit 1e05599

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pkg/config/service.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import (
99
)
1010

1111
// ServiceConfig holds configuration values for the etcd snapshot service.
12-
// The parameters CustomS3Endpoint, s3Prefix and clusterName are optional.
12+
// The parameters CustomS3Endpoint, s3Prefix, clusterName and usePathStyle are optional.
1313
type ServiceConfig struct {
1414
CustomS3Endpoint string `yaml:"customS3Endpoint"`
1515
Bucket string `yaml:"bucket"`
1616
Region string `yaml:"region"`
1717
S3Prefix string `yaml:"s3Prefix"`
1818
ClusterName string `yaml:"clusterName"`
1919
AgeX25519PublicKey string `yaml:"ageX25519PublicKey"`
20+
UsePathStyle bool `yaml:"usePathStyle"`
2021
}
2122

2223
const (
@@ -25,6 +26,7 @@ const (
2526
regionEnvVar = "AWS_REGION"
2627
s3PrefixEnvVar = "S3_PREFIX"
2728
clusterNameEnvVar = "CLUSTER_NAME"
29+
usePathStyleEnvVar = "USE_PATH_STYLE"
2830
ageX25519PublicKeyEnvVar = "AGE_X25519_PUBLIC_KEY"
2931
)
3032

@@ -36,6 +38,7 @@ func GetServiceConfig() *ServiceConfig {
3638
Region: os.Getenv(regionEnvVar),
3739
S3Prefix: os.Getenv(s3PrefixEnvVar),
3840
ClusterName: os.Getenv(clusterNameEnvVar),
41+
UsePathStyle: os.Getenv(usePathStyleEnvVar) == "false",
3942
AgeX25519PublicKey: os.Getenv(ageX25519PublicKeyEnvVar),
4043
}
4144
}

pkg/s3/s3.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ func CreateClientWithCustomEndpoint(ctx context.Context, svcConf *buconfig.Servi
3232
if svcConf.CustomS3Endpoint != "" {
3333
// Ref: https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/endpoints/
3434
o.BaseEndpoint = aws.String(svcConf.CustomS3Endpoint)
35+
// Ref: https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/s3#Options.UsePathStyle
36+
o.UsePathStyle = *aws.Bool(svcConf.UsePathStyle)
3537
}
3638
})
3739

0 commit comments

Comments
 (0)