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:
parent
e6a52810c5
commit
e601fecc04
1 changed files with 9 additions and 10 deletions
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue