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 <noreply@anthropic.com>
This commit is contained in:
jedarden 2026-04-25 10:38:41 -04:00
parent e6a52810c5
commit e601fecc04

View file

@ -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,
}