Skip to content

Commit

Permalink
fix(aws-android-sdk-core): modify region parsing for endpoints in vpc (
Browse files Browse the repository at this point in the history
  • Loading branch information
eeatonaws authored Sep 29, 2022
1 parent a21e3be commit 131d2f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class AwsHostNameUtils {

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

private static final String VPC_NAME = "vpce";

/**
* @deprecated in favor of {@link #parseRegionName(String, String)}.
Expand Down Expand Up @@ -117,8 +119,18 @@ private static String parseStandardRegionName(final String fragment) {
return "us-east-1";
}

// host was 'service.[region].amazonaws.com'.
// host was 'service.[region].amazonaws.com'. or 'service.[region].vpce.amazonaws.com'
String region = fragment.substring(index + 1);
if (region.equals(VPC_NAME)) {
String[] partsOfFragment = fragment.split("\\.");
if (partsOfFragment.length >= 2) {
// host was 'service.[region].vpce.amazonaws.com'
region = partsOfFragment[partsOfFragment.length - 2];
} else {
// guess us-east-1 for lack of a better option
return "us-east-1";
}
}

// Special case for iam.us-gov.amazonaws.com, which is actually
// us-gov-west-1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ public void testStandard() {
"bucket.name.with.periods.s3.eu-west-1.amazonaws.com", "s3"));
}

@Test
public void testVpcEndpoint() {
assertEquals("us-west-2", AwsHostNameUtils.parseRegionName(
"bucket.vpce-1234.s3.us-west-2.vpce.amazonaws.com", "s3"));
}

@Test
public void testBJS() {
// Verify that BJS endpoints parse correctly even though they're
Expand Down

0 comments on commit 131d2f4

Please sign in to comment.