Skip to content

Commit

Permalink
feat: add support for UsePathStyle in ServiceConfig
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cgrard authored and frezbo committed Aug 27, 2024
1 parent ec893b4 commit 1e05599
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/config/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
)

// ServiceConfig holds configuration values for the etcd snapshot service.
// The parameters CustomS3Endpoint, s3Prefix and clusterName are optional.
// The parameters CustomS3Endpoint, s3Prefix, clusterName and usePathStyle are optional.
type ServiceConfig struct {
CustomS3Endpoint string `yaml:"customS3Endpoint"`
Bucket string `yaml:"bucket"`
Region string `yaml:"region"`
S3Prefix string `yaml:"s3Prefix"`
ClusterName string `yaml:"clusterName"`
AgeX25519PublicKey string `yaml:"ageX25519PublicKey"`
UsePathStyle bool `yaml:"usePathStyle"`
}

const (
Expand All @@ -25,6 +26,7 @@ const (
regionEnvVar = "AWS_REGION"
s3PrefixEnvVar = "S3_PREFIX"
clusterNameEnvVar = "CLUSTER_NAME"
usePathStyleEnvVar = "USE_PATH_STYLE"
ageX25519PublicKeyEnvVar = "AGE_X25519_PUBLIC_KEY"
)

Expand All @@ -36,6 +38,7 @@ func GetServiceConfig() *ServiceConfig {
Region: os.Getenv(regionEnvVar),
S3Prefix: os.Getenv(s3PrefixEnvVar),
ClusterName: os.Getenv(clusterNameEnvVar),
UsePathStyle: os.Getenv(usePathStyleEnvVar) == "false",
AgeX25519PublicKey: os.Getenv(ageX25519PublicKeyEnvVar),
}
}
2 changes: 2 additions & 0 deletions pkg/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func CreateClientWithCustomEndpoint(ctx context.Context, svcConf *buconfig.Servi
if svcConf.CustomS3Endpoint != "" {
// Ref: https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/endpoints/
o.BaseEndpoint = aws.String(svcConf.CustomS3Endpoint)
// Ref: https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/s3#Options.UsePathStyle
o.UsePathStyle = *aws.Bool(svcConf.UsePathStyle)
}
})

Expand Down

0 comments on commit 1e05599

Please sign in to comment.