Skip to content

Commit

Permalink
Use SDK's built-in resolver for S3Path.GetHTTPsUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
rifelpet committed Jan 9, 2025
1 parent 86aef04 commit dffc224
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions util/pkg/vfs/s3fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,13 +561,18 @@ func (p *S3Path) GetHTTPsUrl(dualstack bool) (string, error) {
return "", fmt.Errorf("failed to get bucket details for %q: %w", p.String(), err)
}

var url string
if dualstack {
url = fmt.Sprintf("https://s3.dualstack.%s.amazonaws.com/%s/%s", bucketDetails.region, bucketDetails.name, p.Key())
} else {
url = fmt.Sprintf("https://%s.s3.%s.amazonaws.com/%s", bucketDetails.name, bucketDetails.region, p.Key())
resolver := s3.NewDefaultEndpointResolverV2()
endpoint, err := resolver.ResolveEndpoint(ctx, s3.EndpointParameters{
Bucket: aws.String(bucketDetails.name),
Region: aws.String(bucketDetails.region),
UseDualStack: aws.Bool(dualstack),
})
if err != nil {
return "", fmt.Errorf("failed to resolve endpoint for %q: %w", p.String(), err)
}
return strings.TrimSuffix(url, "/"), nil

endpoint.URI.Path = path.Join(endpoint.URI.Path, p.Key())
return endpoint.URI.String(), nil
}

func (p *S3Path) IsBucketPublic(ctx context.Context) (bool, error) {
Expand Down

0 comments on commit dffc224

Please sign in to comment.