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

Make EndpointToRegion.guessRegionOrRegionNameForEndpoint tolerate the format 127.0.0.1:1234 #2256

Merged
merged 1 commit into from
Apr 3, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.amazonaws.annotation.SdkProtectedApi;
import com.amazonaws.util.AwsHostNameUtils;
import java.net.URI;
import java.net.URISyntaxException;

/**
* Utilities to attempt to convert from a hostname/endpoint to an AWS region.
Expand Down Expand Up @@ -68,7 +69,12 @@ private static RegionOrRegionName guessRegionOrRegionNameForEndpoint(String endp
return new RegionOrRegionName();
}

String host = URI.create(endpoint).getHost();
String host = null;
try {
host = new URI(endpoint).getHost();
} catch (URISyntaxException x) {
// proceed
}
if (host == null) {
host = URI.create("http://" + endpoint).getHost();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ public void guessRegionForHostname_basedOnFollowingServiceName() {
verifyRegionAndPartitionForHostname("us-gov-west-1", "aws-us-gov", "iam.us-gov-west-1.banana.com", "iam");
}

@Test
public void guessRegionForHostname_ipAddress() {
assertNull(guessRegionNameForEndpoint("http://localhost"));
assertNull(guessRegionNameForEndpoint("http://localhost:1234"));
assertNull(guessRegionNameForEndpoint("http://127.0.0.1"));
assertNull(guessRegionNameForEndpoint("http://127.0.0.1:1234"));
assertNull(guessRegionNameForEndpoint("localhost"));
assertNull(guessRegionNameForEndpoint("localhost:1234"));
assertNull(guessRegionNameForEndpoint("127.0.0.1"));
assertNull(guessRegionNameForEndpoint("127.0.0.1:1234"));
}

/**
* We migrated from AwsHostNameUtils.parseRegion to EndpointToRegion.guessRegionNameForHostname, because EndpointToRegion
* can consider the contents of endpoints.json.
Expand Down