Skip to content

Commit

Permalink
Merge pull request #210 from kaovilai/bucket-region-hinting-anonymous…
Browse files Browse the repository at this point in the history
…-creds

Set hinting region to use for GetBucketRegion()
  • Loading branch information
sseago committed Jul 26, 2024
2 parents dedaacf + 156fb10 commit add8312
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/210-kaovilai
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix region discovery after aws-sdk-go-v2
27 changes: 13 additions & 14 deletions velero-plugin-for-aws/object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,33 +139,32 @@ func (o *ObjectStore) Init(config map[string]string) error {
}
}

cfg, err := newConfigBuilder(o.log).WithRegion(region).
WithProfile(credentialProfile).
WithCredentialsFile(credentialsFile).
WithTLSSettings(insecureSkipTLSVerify, caCert).Build()
if err != nil {
return errors.WithStack(err)
}

// AWS (not an alternate S3-compatible API) and region not
// explicitly specified: determine the bucket's region
// GetBucketRegion will attempt to get the region for a bucket using the
// client's configured region to determine which AWS partition to perform the query on.
if s3URL == "" && region == "" {
cfg, err := newConfigBuilder(o.log).WithTLSSettings(insecureSkipTLSVerify, caCert).Build()
regionClient, err := newS3Client(cfg, s3URL, s3ForcePathStyle)
if err != nil {
return errors.WithStack(err)
}
client, err := newS3Client(cfg, s3URL, s3ForcePathStyle)
if err != nil {
return errors.WithStack(err)
}
region, err = manager.GetBucketRegion(context.Background(), client, bucket)
region, err = manager.GetBucketRegion(context.Background(), regionClient, bucket, func(o *s3.Options) { o.Region = "us-east-1" })
if err != nil {
o.log.Errorf("Failed to determine bucket's region bucket: %s, error: %v", bucket, err)
return err
}
if region == "" {
return fmt.Errorf("unable to determine bucket's region, bucket: %s", bucket)
}
}

cfg, err := newConfigBuilder(o.log).WithRegion(region).
WithProfile(credentialProfile).
WithCredentialsFile(credentialsFile).
WithTLSSettings(insecureSkipTLSVerify, caCert).Build()
if err != nil {
return errors.WithStack(err)
cfg.Region = region
}

client, err := newS3Client(cfg, s3URL, s3ForcePathStyle)
Expand Down

0 comments on commit add8312

Please sign in to comment.