Skip to content

Commit

Permalink
Modify S3 endpoint regex pattern to support VPC endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Calcote authored and gaul committed Jul 27, 2024
1 parent f4e986f commit ddfb2ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public class AwsHostNameUtils {

private static final Pattern S3_ENDPOINT_PATTERN = Pattern.compile("^(?:.+\\.)?s3[.-]([a-z0-9-]+)$");
private static final Pattern S3_ENDPOINT_PATTERN = Pattern.compile("^(?:.+\\.)?s3[.\\-]([a-z0-9-]+)(?>\\.[a-z0-9-]+)*$");

private static final Pattern STANDARD_CLOUDSEARCH_ENDPOINT_PATTERN = Pattern.compile("^(?:.+\\.)?([a-z0-9-]+)\\.cloudsearch$");

Expand Down Expand Up @@ -107,7 +107,7 @@ private static String parseStandardRegionName(final String fragment) {

Matcher matcher = S3_ENDPOINT_PATTERN.matcher(fragment);
if (matcher.matches()) {
// host was 'bucket.s3-[region].amazonaws.com'.
// host was '[whatever].s3[.|-]-[region].[whatever].amazonaws.com
return matcher.group(1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,20 @@ public void testParseService() {
"s3"
);


Assert.assertEquals(
AwsHostNameUtils.parseServiceName(URI.create("https://test-bucket.s3.cn-north-1.amazonaws.com.cn")),
"s3"
);
}

@Test
// test s3 virtual private cloud URL
public void testVpcUrl() {
Assert.assertEquals(
AwsHostNameUtils.parseServiceName(
URI.create("https://bucket.vpce-0037af66cf9b0cc5e-zop31d9j.s3.us-east-1.vpce.amazonaws.com")
),
"s3"
);
}
}

0 comments on commit ddfb2ea

Please sign in to comment.