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
1 changed files with 5 additions and 9 deletions

View File

@ -26,6 +26,8 @@ import (
"sync"
"time"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"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
func (f *Fs) getBucketLocation(ctx context.Context, bucket string) (string, error) {
req := s3.GetBucketLocationInput{
Bucket: &bucket,
}
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)
region, err := s3manager.GetBucketRegion(ctx, f.ses, bucket, "", func(r *request.Request) {
r.Config.S3ForcePathStyle = aws.Bool(f.opt.ForcePathStyle)
})
if err != nil {
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