feat: auto-enable path-style addressing when a custom endpoint is set
When AWS_ENDPOINT_URL_S3 or AWS_ENDPOINT_URL is set (typically because the runtime is pointing at a local MinIO/S3-compatible endpoint), enable path-style addressing on the S3 client. Without this requests fail because MinIO doesn't implement virtual-hosted style addressing out of the box. Production deployments leave those env vars unset and continue talking to real AWS S3 with virtual-hosted style, so no behaviour change there. Both New() and NewS3() share a s3ClientOptions helper that applies the toggle. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+29
@@ -40,6 +40,35 @@ func (m *mockPresigner) PresignGetObject(ctx context.Context, params *s3.GetObje
|
||||
return m.presignFunc(ctx, params, optFns...)
|
||||
}
|
||||
|
||||
// Test path-style toggle
|
||||
|
||||
func TestS3ClientOptions_PathStyleTogglesOnCustomEndpoint(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
envVar string
|
||||
value string
|
||||
expected bool
|
||||
}{
|
||||
{name: "no env var → virtual-hosted", envVar: "", expected: false},
|
||||
{name: "AWS_ENDPOINT_URL_S3 set → path-style", envVar: "AWS_ENDPOINT_URL_S3", value: "http://minio:9000", expected: true},
|
||||
{name: "AWS_ENDPOINT_URL set → path-style", envVar: "AWS_ENDPOINT_URL", value: "http://minio:9000", expected: true},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Setenv("AWS_ENDPOINT_URL", "")
|
||||
t.Setenv("AWS_ENDPOINT_URL_S3", "")
|
||||
if tc.envVar != "" {
|
||||
t.Setenv(tc.envVar, tc.value)
|
||||
}
|
||||
opts := s3.Options{}
|
||||
s3ClientOptions(&opts)
|
||||
if opts.UsePathStyle != tc.expected {
|
||||
t.Fatalf("UsePathStyle = %v, want %v", opts.UsePathStyle, tc.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Test NewS3 constructor
|
||||
|
||||
func TestNewS3(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user