Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-android-sdk-core): modify region parsing for endpoints in vpc #3024

Merged
merged 2 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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