From e601fecc04781a59e9ff2643c739cce2e05fde53 Mon Sep 17 00:00:00 2001 From: jedarden Date: Sat, 25 Apr 2026 10:38:41 -0400 Subject: [PATCH] fix(worker): update B2 client for S3-compatible API (ARMOR/B2) Remove custom endpoint resolver and use AWS SDK's standard approach for S3-compatible endpoints: - Use config.WithRegion("auto") for custom endpoints - Set BaseEndpoint directly via s3.NewFromConfig options - Add UsePathStyle for B2 compatibility This fixes the 'Invalid region: region was not a valid DNS name' error that was preventing replay uploads. The deployment manifest already sets ACB_B2_REGION to empty string to avoid conflicts. Co-Authored-By: Claude Opus 4.7 --- cmd/acb-worker/b2.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/cmd/acb-worker/b2.go b/cmd/acb-worker/b2.go index 138761b..543ab4d 100644 --- a/cmd/acb-worker/b2.go +++ b/cmd/acb-worker/b2.go @@ -21,29 +21,28 @@ type B2Client struct { // NewB2Client creates a new B2 client. func NewB2Client(cfg *Config) *B2Client { - // Create custom endpoint resolver for B2 (S3-compatible) - customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) { - return aws.Endpoint{ - URL: cfg.B2Endpoint, - SigningRegion: cfg.B2Region, - }, nil - }) - // Load AWS config with B2 credentials + // Use region "auto" for custom S3-compatible endpoints (ARMOR/B2) awsCfg, err := config.LoadDefaultConfig(context.TODO(), config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider( cfg.B2AccessKey, cfg.B2SecretKey, "", )), - config.WithEndpointResolverWithOptions(customResolver), + config.WithRegion("auto"), ) if err != nil { panic(fmt.Sprintf("failed to load AWS config: %v", err)) } + // Create S3 client with custom endpoint (ARMOR proxy wrapping B2) + client := s3.NewFromConfig(awsCfg, func(o *s3.Options) { + o.BaseEndpoint = aws.String(cfg.B2Endpoint) + o.UsePathStyle = true // Required for ARMOR/B2 S3-compatible API + }) + return &B2Client{ - client: s3.NewFromConfig(awsCfg), + client: client, bucket: cfg.B2Bucket, endpoint: cfg.B2Endpoint, }