Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to explicitly specify bucket addressing style for S3 client #368

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,18 @@ type EncryptOpts struct {
ServerSideCustomerKey string
}

// AddressingStyle is a type of bucket (and also its content) addressing used by the S3 client and supported by the server
type AddressingStyle int

const (
AutoDetectStyle AddressingStyle = iota
PathStyle
VirtualHostedStyle
)

type S3ClientOpts struct {
Endpoint string
AddressingStyle AddressingStyle
Region string
Secure bool
AccessKey string
Expand Down Expand Up @@ -147,7 +157,15 @@ func NewS3Client(ctx context.Context, opts S3ClientOpts) (S3Client, error) {
return nil, errors.WithStack(err)
}

minioOpts := &minio.Options{Creds: credentials, Secure: s3cli.Secure, Region: s3cli.Region}
var bucketLookupType minio.BucketLookupType
if s3cli.AddressingStyle == PathStyle {
bucketLookupType = minio.BucketLookupPath
} else if s3cli.AddressingStyle == VirtualHostedStyle {
bucketLookupType = minio.BucketLookupDNS
} else {
bucketLookupType = minio.BucketLookupAuto
}
minioOpts := &minio.Options{Creds: credentials, Secure: s3cli.Secure, Region: s3cli.Region, BucketLookup: bucketLookupType}
minioClient, err = minio.New(s3cli.Endpoint, minioOpts)
if err != nil {
return nil, errors.WithStack(err)
Expand Down
1 change: 1 addition & 0 deletions s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestNewS3Client(t *testing.T) {
assert.Equal(t, opts.AccessKey, s3cli.AccessKey)
assert.Equal(t, opts.Trace, s3cli.Trace)
assert.Equal(t, opts.EncryptOpts, s3cli.EncryptOpts)
assert.Equal(t, opts.AddressingStyle, s3cli.AddressingStyle)
// s3cli.minioClient.
// s3client.minioClient
}
Expand Down