diff --git a/cmd/acb-worker/b2.go b/cmd/acb-worker/b2.go index 91259a5..fea7561 100644 --- a/cmd/acb-worker/b2.go +++ b/cmd/acb-worker/b2.go @@ -5,11 +5,13 @@ import ( "bytes" "context" "fmt" + "net/url" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/s3" + smithyendpoints "github.com/aws/smithy-go/endpoints" ) // B2Client handles B2 bucket operations (S3-compatible). @@ -21,6 +23,12 @@ type B2Client struct { // NewB2Client creates a new B2 client. func NewB2Client(cfg *Config) *B2Client { + // Parse and validate the custom endpoint + endpointURL, err := url.Parse(cfg.B2Endpoint) + if err != nil { + panic(fmt.Sprintf("failed to parse B2 endpoint: %v", err)) + } + // Load AWS config with B2 credentials // For S3-compatible endpoints (ARMOR/B2), the region is not used // but must be set to a valid value for the SDK @@ -37,9 +45,11 @@ func NewB2Client(cfg *Config) *B2Client { } // Create S3 client with custom endpoint (ARMOR proxy wrapping B2) + // Use custom EndpointResolverV2 to bypass endpoint rules entirely client := s3.NewFromConfig(awsCfg, func(o *s3.Options) { - o.BaseEndpoint = aws.String(cfg.B2Endpoint) - o.UsePathStyle = true // Required for ARMOR/B2 S3-compatible API + o.EndpointResolverV2 = &customEndpointResolver{ + endpointURL: *endpointURL, + } }) return &B2Client{ @@ -122,3 +132,14 @@ func (c *B2Client) List(ctx context.Context, prefix string) ([]string, error) { func (c *B2Client) Endpoint() string { return c.endpoint } + +// customEndpointResolver implements s3.EndpointResolverV2 for custom S3-compatible endpoints. +type customEndpointResolver struct { + endpointURL url.URL +} + +func (r *customEndpointResolver) ResolveEndpoint(ctx context.Context, params s3.EndpointParameters) (smithyendpoints.Endpoint, error) { + return smithyendpoints.Endpoint{ + URI: r.endpointURL, + }, nil +}