Skip to content

Commit

Permalink
Merge pull request #2256 from jglick/EndpointToRegion
Browse files Browse the repository at this point in the history
Make EndpointToRegion.guessRegionOrRegionNameForEndpoint tolerate the format 127.0.0.1:1234
  • Loading branch information
zoewangg committed Apr 3, 2020
2 parents 30c2048 + 78f8755 commit 780ed5f
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 @@ -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

0 comments on commit 780ed5f

Please sign in to comment.