Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7941a52a32 | |||
| b9fdb056a7 | |||
| 46450f8f37 | |||
| a4dedab2f5 | |||
| 1620565ae6 |
@@ -2,6 +2,18 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [0.4.1] - 2026-04-19
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
|
||||
- *(deps)* Update aws-sdk-go-v2 monorepo (#102)
|
||||
|
||||
## [0.4.0] - 2026-04-17
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
- Auto-enable path-style addressing when a custom endpoint is set (#99)
|
||||
|
||||
## [0.3.0] - 2026-04-16
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
@@ -4,8 +4,8 @@ go 1.24
|
||||
|
||||
require (
|
||||
github.com/aws/aws-sdk-go-v2 v1.41.5
|
||||
github.com/aws/aws-sdk-go-v2/config v1.32.14
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager v0.1.15
|
||||
github.com/aws/aws-sdk-go-v2/config v1.32.15
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager v0.1.16
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.99.0
|
||||
)
|
||||
|
||||
@@ -15,7 +15,6 @@ require (
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.21 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.21 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.21 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.22 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.13 // indirect
|
||||
|
||||
@@ -2,20 +2,18 @@ github.com/aws/aws-sdk-go-v2 v1.41.5 h1:dj5kopbwUsVUVFgO4Fi5BIT3t4WyqIDjGKCangnV
|
||||
github.com/aws/aws-sdk-go-v2 v1.41.5/go.mod h1:mwsPRE8ceUUpiTgF7QmQIJ7lgsKUPQOUl3o72QBrE1o=
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.8 h1:eBMB84YGghSocM7PsjmmPffTa+1FBUeNvGvFou6V/4o=
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.8/go.mod h1:lyw7GFp3qENLh7kwzf7iMzAxDn+NzjXEAGjKS2UOKqI=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.32.14 h1:opVIRo/ZbbI8OIqSOKmpFaY7IwfFUOCCXBsUpJOwDdI=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.32.14/go.mod h1:U4/V0uKxh0Tl5sxmCBZ3AecYny4UNlVmObYjKuuaiOo=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.32.15 h1:i7rHbaySnBXGvCkDndaBU8f3EAlRVgViwNfkwFUrXgE=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.32.15/go.mod h1:yLJzL0IkI9+4BwjPSOueyHzppJj3t0dhK5tbmmcFk5Q=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.14 h1:n+UcGWAIZHkXzYt87uMFBv/l8THYELoX6gVcUvgl6fI=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.14/go.mod h1:cJKuyWB59Mqi0jM3nFYQRmnHVQIcgoxjEMAbLkpr62w=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.21 h1:NUS3K4BTDArQqNu2ih7yeDLaS3bmHD0YndtA6UP884g=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.21/go.mod h1:YWNWJQNjKigKY1RHVJCuupeWDrrHjRqHm0N9rdrWzYI=
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager v0.1.15 h1:92MfpwB6KjsPIEq9g3DniRPxOe92ew5hUz1h8W8cX7E=
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager v0.1.15/go.mod h1:7O129SmOn4acM++3oVfTLAeHmNOsj0y7AA7zmbgnGOk=
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager v0.1.16 h1:n8TmP5vlknh1B/mVNrNgQfSvQy0isR9B9IgADdwuhhY=
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager v0.1.16/go.mod h1:Iu9wL4lqscFF6ByhqyDO8mgvCUwGn5bqWr7fuOgUjTA=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.21 h1:Rgg6wvjjtX8bNHcvi9OnXWwcE0a2vGpbwmtICOsvcf4=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.21/go.mod h1:A/kJFst/nm//cyqonihbdpQZwiUhhzpqTsdbhDdRF9c=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.21 h1:PEgGVtPoB6NTpPrBgqSE5hE/o47Ij9qk/SEZFbUOe9A=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.21/go.mod h1:p+hz+PRAYlY3zcpJhPwXlLC4C+kqn70WIHwnzAfs6ps=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6 h1:qYQ4pzQ2Oz6WpQ8T3HvGHnZydA72MnLuFK9tJwmrbHw=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6/go.mod h1:O3h0IK87yXci+kg6flUKzJnWeziQUKciKrLjcatSNcY=
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.22 h1:rWyie/PxDRIdhNf4DzRk0lvjVOqFJuNnO8WwaIRVxzQ=
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.22/go.mod h1:zd/JsJ4P7oGfUhXn1VyLqaRZwPmZwg44Jf2dS84Dm3Y=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7 h1:5EniKhLZe4xzL7a+fU3C2tfUN4nWIqlLesfrjkuPFTY=
|
||||
|
||||
@@ -3,6 +3,7 @@ package storage
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
@@ -12,6 +13,19 @@ import (
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
)
|
||||
|
||||
// s3ClientOptions returns the per-client overrides applied to every S3 client
|
||||
// constructed by this package. When the AWS_ENDPOINT_URL_S3 (or
|
||||
// AWS_ENDPOINT_URL) env var is set — typically because the runtime is
|
||||
// pointing at a local MinIO/S3-compatible endpoint — path-style addressing
|
||||
// is enabled so requests look like `http://host:9000/bucket/key` instead of
|
||||
// `http://bucket.host:9000/key`. Production deployments leave those vars
|
||||
// unset and continue talking to real S3 with virtual-hosted style.
|
||||
func s3ClientOptions(o *s3.Options) {
|
||||
if os.Getenv("AWS_ENDPOINT_URL_S3") != "" || os.Getenv("AWS_ENDPOINT_URL") != "" {
|
||||
o.UsePathStyle = true
|
||||
}
|
||||
}
|
||||
|
||||
// Uploader is the interface for uploading objects to S3 using the transfer manager
|
||||
type Uploader interface {
|
||||
UploadObject(ctx context.Context, input *transfermanager.UploadObjectInput, opts ...func(*transfermanager.Options)) (*transfermanager.UploadObjectOutput, error)
|
||||
@@ -131,7 +145,7 @@ func New(bucket string) (*S3, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client := s3.NewFromConfig(cfg)
|
||||
client := s3.NewFromConfig(cfg, s3ClientOptions)
|
||||
uploader := transfermanager.New(client, func(o *transfermanager.Options) {
|
||||
o.PartSizeBytes = 5 * 1024 * 1024
|
||||
})
|
||||
@@ -147,7 +161,7 @@ func New(bucket string) (*S3, error) {
|
||||
// NewS3 creates a new S3 storage instance using direct PutObject
|
||||
// This is useful when you want more control over the AWS configuration
|
||||
func NewS3(cfg aws.Config, bucket string) *S3 {
|
||||
client := s3.NewFromConfig(cfg)
|
||||
client := s3.NewFromConfig(cfg, s3ClientOptions)
|
||||
return &S3{
|
||||
bucket: bucket,
|
||||
directSvc: client,
|
||||
|
||||
+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