s3: use different strategy to resolve s3 region

The API endpoint GetBucketLocation requires
top level permission.

If we do an authenticated head request to a bucket, the bucket location will be returned in the HTTP headers.

Fixes #5066
This commit is contained in:
Anthony Pessy 2022-10-29 09:37:08 +02:00 committed by Nick Craig-Wood
parent 2617610741
commit 10c884552c

View file

@ -26,6 +26,8 @@ import (
"sync" "sync"
"time" "time"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/corehandlers" "github.com/aws/aws-sdk-go/aws/corehandlers"
@ -2992,19 +2994,13 @@ func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error) {
// Gets the bucket location // Gets the bucket location
func (f *Fs) getBucketLocation(ctx context.Context, bucket string) (string, error) { func (f *Fs) getBucketLocation(ctx context.Context, bucket string) (string, error) {
req := s3.GetBucketLocationInput{ region, err := s3manager.GetBucketRegion(ctx, f.ses, bucket, "", func(r *request.Request) {
Bucket: &bucket, r.Config.S3ForcePathStyle = aws.Bool(f.opt.ForcePathStyle)
}
var resp *s3.GetBucketLocationOutput
var err error
err = f.pacer.Call(func() (bool, error) {
resp, err = f.c.GetBucketLocation(&req)
return f.shouldRetry(ctx, err)
}) })
if err != nil { if err != nil {
return "", err return "", err
} }
return s3.NormalizeBucketLocation(aws.StringValue(resp.LocationConstraint)), nil return region, nil
} }
// Updates the region for the bucket by reading the region from the // Updates the region for the bucket by reading the region from the