Skip to content

Commit f15d17e

Browse files
committed
feat: s3 support path-style access
1 parent d1f148f commit f15d17e

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

pkg/cli/workspace.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type workspaceProvider struct {
1414
DataHome string `usage:"The data home directory or bucket name" env:"WORKSPACE_PROVIDER_DATA_HOME"`
1515
S3Bucket string `usage:"The S3 bucket name" name:"s3-bucket" env:"WORKSPACE_PROVIDER_S3_BUCKET"`
1616
S3BaseEndpoint string `usage:"The S3 base endpoint to use with S3 compatible providers" name:"s3-base-endpoint" env:"WORKSPACE_PROVIDER_S3_BASE_ENDPOINT"`
17+
S3UsePathStyle bool `usage:"Use path style addressing for S3 compatible providers" name:"s3-use-path-style" env:"WORKSPACE_PROVIDER_S3_USE_PATH_STYLE"`
1718

1819
client *client.Client
1920
}
@@ -64,6 +65,7 @@ func (w *workspaceProvider) PersistentPre(cmd *cobra.Command, _ []string) error
6465
DirectoryDataHome: w.DataHome,
6566
S3BucketName: w.S3Bucket,
6667
S3BaseEndpoint: w.S3BaseEndpoint,
68+
S3UsePathStyle: w.S3UsePathStyle,
6769
})
6870

6971
return err

pkg/client/client.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Options struct {
4141
DirectoryDataHome string
4242
S3BucketName string
4343
S3BaseEndpoint string
44+
S3UsePathStyle bool
4445
}
4546

4647
func complete(opts ...Options) Options {
@@ -56,6 +57,7 @@ func complete(opts ...Options) Options {
5657
if o.S3BaseEndpoint != "" {
5758
opt.S3BaseEndpoint = o.S3BaseEndpoint
5859
}
60+
opt.S3UsePathStyle = o.S3UsePathStyle
5961
}
6062

6163
if opt.DirectoryDataHome == "" {
@@ -71,7 +73,7 @@ func New(ctx context.Context, opts ...Options) (*Client, error) {
7173
var s3 workspaceFactory
7274
if opt.S3BucketName != "" {
7375
var err error
74-
s3, err = newS3(ctx, opt.S3BucketName, opt.S3BaseEndpoint)
76+
s3, err = newS3(ctx, opt.S3BucketName, opt.S3BaseEndpoint, opt.S3UsePathStyle)
7577
if err != nil {
7678
return nil, err
7779
}

pkg/client/directory_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestMain(m *testing.M) {
2929
dirPrv, _ = directoryFactory.New(directoryTestingID)
3030

3131
if !skipS3Tests {
32-
s3Factory, _ = newS3(context.Background(), os.Getenv("WORKSPACE_PROVIDER_S3_BUCKET"), os.Getenv("WORKSPACE_PROVIDER_S3_BASE_ENDPOINT"))
32+
s3Factory, _ = newS3(context.Background(), os.Getenv("WORKSPACE_PROVIDER_S3_BUCKET"), os.Getenv("WORKSPACE_PROVIDER_S3_BASE_ENDPOINT"), os.Getenv("WORKSPACE_PROVIDER_S3_USE_PATH_STYLE") == "true")
3333
// This won't ever error because it doesn't create anything.
3434
s3TestingID = s3Factory.Create()
3535

pkg/client/s3.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/gabriel-vasile/mimetype"
2222
)
2323

24-
func newS3(ctx context.Context, bucket, baseEndpoint string) (workspaceFactory, error) {
24+
func newS3(ctx context.Context, bucket string, baseEndpoint string, usePathStyle bool) (workspaceFactory, error) {
2525
cfg, err := config.LoadDefaultConfig(ctx)
2626
if err != nil {
2727
return nil, err
@@ -31,6 +31,7 @@ func newS3(ctx context.Context, bucket, baseEndpoint string) (workspaceFactory,
3131
if baseEndpoint != "" {
3232
o.BaseEndpoint = aws.String(baseEndpoint)
3333
}
34+
o.UsePathStyle = usePathStyle // often required e.g. for MinIO which requires extra configuration for virtual hosted-style requests
3435
})
3536
return &s3Provider{
3637
bucket: bucket,

0 commit comments

Comments
 (0)