Skip to content

Commit

Permalink
Set hinting region to use from GetBucketRegion()
Browse files Browse the repository at this point in the history
Signed-off-by: Tiger Kaovilai <[email protected]>
  • Loading branch information
kaovilai committed Jul 16, 2024
1 parent 26bf625 commit 2183997
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/xxxx-kaovilai
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix region discovery after aws-sdk-go-v2
5 changes: 5 additions & 0 deletions velero-plugin-for-aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func (cb *configBuilder) WithRegion(region string) *configBuilder {
return cb
}

func (cb *configBuilder) WithAnonymousCredentials() *configBuilder {
cb.opts = append(cb.opts, config.WithCredentialsProvider(aws.AnonymousCredentials{}))
return cb
}

func (cb *configBuilder) WithProfile(profile string) *configBuilder {
cb.opts = append(cb.opts, config.WithSharedConfigProfile(profile))
return cb
Expand Down
12 changes: 10 additions & 2 deletions velero-plugin-for-aws/object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,20 @@ func (o *ObjectStore) Init(config map[string]string) error {

// 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.
// The request will not be signed, and will not use your AWS credentials.
if s3URL == "" && region == "" {
cfg, err := newConfigBuilder(o.log).WithTLSSettings(insecureSkipTLSVerify, caCert).Build()
regionCfg, err := newConfigBuilder(o.log).WithTLSSettings(insecureSkipTLSVerify, caCert).
// configures anonymous credentials
WithAnonymousCredentials().
// configures region for GetBucketRegion to query from
WithRegion("us-east-1").
Build()
if err != nil {
return errors.WithStack(err)
}
client, err := newS3Client(cfg, s3URL, s3ForcePathStyle)
client, err := newS3Client(regionCfg, s3URL, s3ForcePathStyle)
if err != nil {
return errors.WithStack(err)
}
Expand Down

0 comments on commit 2183997

Please sign in to comment.