Modify S3 endpoint regex pattern to support VPC endpoints.

This commit is contained in:
John Calcote
2024-07-03 18:21:42 +00:00
committed by Andrew Gaul
parent f4e986f8fb
commit ddfb2ea77f
2 changed files with 13 additions and 3 deletions
@@ -26,7 +26,7 @@ import java.util.regex.Pattern;
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$");
@@ -107,7 +107,7 @@ public class AwsHostNameUtils {
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);
}
@@ -52,10 +52,20 @@ public class AwsHostNameUtilsTest {
"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"
);
}
}