Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to detect 5 parts s3 virtual hosted-style requests #314

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions detect_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func (d *S3Detector) detectHTTP(src string) (string, bool, error) {
return d.detectPathStyle(hostParts[0], parts[1:])
} else if len(hostParts) == 4 {
return d.detectVhostStyle(hostParts[1], hostParts[0], parts[1:])
} else if len(hostParts) == 5 && hostParts[1] == "s3" {
return d.detectNewVhostStyle(hostParts[2], hostParts[0], parts[1:])
} else {
return "", false, fmt.Errorf(
"URL is not a valid S3 URL")
Expand All @@ -59,3 +61,13 @@ func (d *S3Detector) detectVhostStyle(region, bucket string, parts []string) (st

return "s3::" + url.String(), true, nil
}

func (d *S3Detector) detectNewVhostStyle(region, bucket string, parts []string) (string, bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: I wonder what the new, new name will be if AWS adds a new 6 parts vhost-style url

urlStr := fmt.Sprintf("https://s3.%s.amazonaws.com/%s/%s", region, bucket, strings.Join(parts, "/"))
url, err := url.Parse(urlStr)
if err != nil {
return "", false, fmt.Errorf("error parsing S3 URL: %s", err)
}

return "s3::" + url.String(), true, nil
}
5 changes: 5 additions & 0 deletions detect_s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func TestS3Detector(t *testing.T) {
"bucket.s3-eu-west-1.amazonaws.com/foo/bar.baz",
"s3::https://s3-eu-west-1.amazonaws.com/bucket/foo/bar.baz",
},
// 5 parts Virtual hosted-style
{
"bucket.s3.eu-west-1.amazonaws.com/foo/bar.baz",
"s3::https://s3.eu-west-1.amazonaws.com/bucket/foo/bar.baz",
},
// Path style
{
"s3.amazonaws.com/bucket/foo",
Expand Down