diff --git a/detect_s3.go b/detect_s3.go index 8e0f4a03b..89f3c35dc 100644 --- a/detect_s3.go +++ b/detect_s3.go @@ -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") @@ -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) { + 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 +} diff --git a/detect_s3_test.go b/detect_s3_test.go index f410c785c..6aceafd8f 100644 --- a/detect_s3_test.go +++ b/detect_s3_test.go @@ -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",