Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit ddfb2ea

Browse files
John Calcotegaul
authored andcommitted
Modify S3 endpoint regex pattern to support VPC endpoints.
1 parent f4e986f commit ddfb2ea

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

apis/s3/src/main/java/org/jclouds/s3/filters/AwsHostNameUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
public class AwsHostNameUtils {
2828

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

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

@@ -107,7 +107,7 @@ private static String parseStandardRegionName(final String fragment) {
107107

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

apis/s3/src/test/java/org/jclouds/s3/filters/AwsHostNameUtilsTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,20 @@ public void testParseService() {
5252
"s3"
5353
);
5454

55-
5655
Assert.assertEquals(
5756
AwsHostNameUtils.parseServiceName(URI.create("https://test-bucket.s3.cn-north-1.amazonaws.com.cn")),
5857
"s3"
5958
);
6059
}
60+
61+
@Test
62+
// test s3 virtual private cloud URL
63+
public void testVpcUrl() {
64+
Assert.assertEquals(
65+
AwsHostNameUtils.parseServiceName(
66+
URI.create("https://bucket.vpce-0037af66cf9b0cc5e-zop31d9j.s3.us-east-1.vpce.amazonaws.com")
67+
),
68+
"s3"
69+
);
70+
}
6171
}

0 commit comments

Comments
 (0)