Skip to content
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
21 changes: 11 additions & 10 deletions wrapper/src/main/java/software/amazon/jdbc/util/RdsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,37 @@ public class RdsUtils {
"^(?<instance>.+)\\."
+ "(?<dns>proxy-|cluster-|cluster-ro-|cluster-custom-|shardgrp-)?"
+ "(?<domain>[a-zA-Z0-9]+\\.(?<region>[a-zA-Z0-9\\-]+)"
+ "\\.rds\\.amazonaws\\.com\\.?)$",
+ "\\.(rds|rds-fips)\\.amazonaws\\.(com|au|eu|uk)\\.?)$",
Pattern.CASE_INSENSITIVE);

private static final Pattern AURORA_CLUSTER_PATTERN =
Pattern.compile(
"^(?<instance>.+)\\."
+ "(?<dns>cluster-|cluster-ro-)+"
+ "(?<domain>[a-zA-Z0-9]+\\.(?<region>[a-zA-Z0-9\\-]+)"
+ "\\.rds\\.amazonaws\\.com\\.?)$",
+ "\\.(rds|rds-fips)\\.amazonaws\\.(com|au|eu|uk)\\.?)$",
Pattern.CASE_INSENSITIVE);
private static final Pattern AURORA_LIMITLESS_CLUSTER_PATTERN =
Pattern.compile(
"(?<instance>.+)\\."
+ "(?<dns>shardgrp-)+"
+ "(?<domain>[a-zA-Z0-9]+\\.(?<region>[a-zA-Z0-9\\-]+)"
+ "\\.rds\\.(amazonaws\\.com\\.?|amazonaws\\.com\\.cn\\.?|sc2s\\.sgov\\.gov\\.?|c2s\\.ic\\.gov\\.?))$",
+ "\\.(rds|rds-fips)\\.(amazonaws\\.com\\.?|amazonaws\\.eu\\.?|amazonaws\\.au\\.?|amazonaws\\.uk\\.?"
+ "|amazonaws\\.com\\.cn\\.?|sc2s\\.sgov\\.gov\\.?|c2s\\.ic\\.gov\\.?))$",
Pattern.CASE_INSENSITIVE);
private static final Pattern AURORA_CHINA_DNS_PATTERN =
Pattern.compile(
"^(?<instance>.+)\\."
+ "(?<dns>proxy-|cluster-|cluster-ro-|cluster-custom-|shardgrp-)?"
+ "(?<domain>[a-zA-Z0-9]+\\.rds\\.(?<region>[a-zA-Z0-9\\-]+)"
+ "(?<domain>[a-zA-Z0-9]+\\.(rds|rds-fips)\\.(?<region>[a-zA-Z0-9\\-]+)"
+ "\\.amazonaws\\.com\\.cn\\.?)$",
Pattern.CASE_INSENSITIVE);

private static final Pattern AURORA_CHINA_CLUSTER_PATTERN =
Pattern.compile(
"^(?<instance>.+)\\."
+ "(?<dns>cluster-|cluster-ro-)+"
+ "(?<domain>[a-zA-Z0-9]+\\.rds\\.(?<region>[a-zA-Z0-9\\-]+)"
+ "(?<domain>[a-zA-Z0-9]+\\.(rds|rds-fips)\\.(?<region>[a-zA-Z0-9\\-]+)"
+ "\\.amazonaws\\.com\\.cn\\.?)$",
Pattern.CASE_INSENSITIVE);

Expand All @@ -117,37 +118,37 @@ public class RdsUtils {
"^(?<instance>.+)\\."
+ "(?<dns>proxy-|cluster-|cluster-ro-|cluster-custom-|shardgrp-)?"
+ "(?<domain>[a-zA-Z0-9]+\\.(?<region>[a-zA-Z0-9\\-]+)"
+ "\\.rds\\.amazonaws\\.com\\.cn\\.?)$",
+ "\\.(rds|rds-fips)\\.amazonaws\\.com\\.cn\\.?)$",
Pattern.CASE_INSENSITIVE);

private static final Pattern AURORA_OLD_CHINA_CLUSTER_PATTERN =
Pattern.compile(
"^(?<instance>.+)\\."
+ "(?<dns>cluster-|cluster-ro-)+"
+ "(?<domain>[a-zA-Z0-9]+\\.(?<region>[a-zA-Z0-9\\-]+)"
+ "\\.rds\\.amazonaws\\.com\\.cn\\.?)$",
+ "\\.(rds|rds-fips)\\.amazonaws\\.com\\.cn\\.?)$",
Pattern.CASE_INSENSITIVE);

private static final Pattern AURORA_GOV_DNS_PATTERN =
Pattern.compile(
"^(?<instance>.+)\\."
+ "(?<dns>proxy-|cluster-|cluster-ro-|cluster-custom-|shardgrp-)?"
+ "(?<domain>[a-zA-Z0-9]+\\.rds\\.(?<region>[a-zA-Z0-9\\-]+)"
+ "(?<domain>[a-zA-Z0-9]+\\.(rds|rds-fips)\\.(?<region>[a-zA-Z0-9\\-]+)"
+ "\\.(amazonaws\\.com\\.?|c2s\\.ic\\.gov\\.?|sc2s\\.sgov\\.gov\\.?))$",
Pattern.CASE_INSENSITIVE);

private static final Pattern AURORA_GOV_CLUSTER_PATTERN =
Pattern.compile(
"^(?<instance>.+)\\."
+ "(?<dns>cluster-|cluster-ro-)+"
+ "(?<domain>[a-zA-Z0-9]+\\.rds\\.(?<region>[a-zA-Z0-9\\-]+)"
+ "(?<domain>[a-zA-Z0-9]+\\.(rds|rds-fips)\\.(?<region>[a-zA-Z0-9\\-]+)"
+ "\\.(amazonaws\\.com\\.?|c2s\\.ic\\.gov\\.?|sc2s\\.sgov\\.gov\\.?))$",
Pattern.CASE_INSENSITIVE);

private static final Pattern ELB_PATTERN =
Pattern.compile(
"^(?<instance>.+)\\.elb\\."
+ "((?<region>[a-zA-Z0-9\\-]+)\\.amazonaws\\.com\\.?)$",
+ "((?<region>[a-zA-Z0-9\\-]+)\\.amazonaws\\.(com|au|eu|uk)\\.?)$",
Pattern.CASE_INSENSITIVE);

private static final Pattern IP_V4 =
Expand Down
14 changes: 14 additions & 0 deletions wrapper/src/test/java/software/amazon/jdbc/util/RdsUtilsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class RdsUtilsTests {
private static final String usEastRegionLimitlessDbShardGroup =
"database-test-name.shardgrp-XYZ.us-east-2.rds.amazonaws.com";

private static final String euRedshift =
"redshift-test-name.XYZ.eusc-de-east-1.rds.amazonaws.eu";

private static final String chinaRegionCluster =
"database-test-name.cluster-XYZ.rds.cn-northwest-1.amazonaws.com.cn";
private static final String chinaRegionClusterTrailingDot =
Expand Down Expand Up @@ -133,6 +136,7 @@ public void testIsRdsDns() {
assertFalse(target.isRdsDns(usEastRegionElbUrl));
assertFalse(target.isRdsDns(usEastRegionElbUrlTrailingDot));
assertTrue(target.isRdsDns(usEastRegionLimitlessDbShardGroup));
assertTrue(target.isRdsDns(euRedshift));

assertTrue(target.isRdsDns(chinaRegionCluster));
assertTrue(target.isRdsDns(chinaRegionClusterTrailingDot));
Expand Down Expand Up @@ -210,6 +214,9 @@ public void testGetRdsInstanceHostPattern() {
assertEquals(oldChinaExpectedHostPattern, target.getRdsInstanceHostPattern(oldChinaRegionProxy));
assertEquals(oldChinaExpectedHostPattern, target.getRdsInstanceHostPattern(oldChinaRegionCustomDomain));
assertEquals(oldChinaExpectedHostPattern, target.getRdsInstanceHostPattern(oldChinaRegionLimitlessDbShardGroup));

final String euRedshiftExpectedHostPattern = "?.XYZ.eusc-de-east-1.rds.amazonaws.eu";
assertEquals(euRedshiftExpectedHostPattern, target.getRdsInstanceHostPattern(euRedshift));
}

@Test
Expand All @@ -221,6 +228,7 @@ public void testIsRdsClusterDns() {
assertFalse(target.isRdsClusterDns(usEastRegionCustomDomain));
assertFalse(target.isRdsClusterDns(usEastRegionElbUrl));
assertFalse(target.isRdsClusterDns(usEastRegionLimitlessDbShardGroup));
assertFalse(target.isRdsClusterDns(euRedshift));

assertTrue(target.isRdsClusterDns(usIsobEastRegionCluster));
assertTrue(target.isRdsClusterDns(usIsobEastRegionClusterReadOnly));
Expand Down Expand Up @@ -260,6 +268,7 @@ public void testIsWriterClusterDns() {
assertFalse(target.isWriterClusterDns(usEastRegionCustomDomain));
assertFalse(target.isWriterClusterDns(usEastRegionElbUrl));
assertFalse(target.isWriterClusterDns(usEastRegionLimitlessDbShardGroup));
assertFalse(target.isWriterClusterDns(euRedshift));

assertTrue(target.isWriterClusterDns(usIsobEastRegionCluster));
assertFalse(target.isWriterClusterDns(usIsobEastRegionClusterReadOnly));
Expand Down Expand Up @@ -299,6 +308,7 @@ public void testIsReaderClusterDns() {
assertFalse(target.isReaderClusterDns(usEastRegionCustomDomain));
assertFalse(target.isReaderClusterDns(usEastRegionElbUrl));
assertFalse(target.isReaderClusterDns(usEastRegionLimitlessDbShardGroup));
assertFalse(target.isReaderClusterDns(euRedshift));

assertFalse(target.isReaderClusterDns(usIsobEastRegionCluster));
assertTrue(target.isReaderClusterDns(usIsobEastRegionClusterReadOnly));
Expand Down Expand Up @@ -338,6 +348,7 @@ public void testIsLimitlessDbShardGroupDns() {
assertFalse(target.isLimitlessDbShardGroupDns(usEastRegionCustomDomain));
assertFalse(target.isLimitlessDbShardGroupDns(usEastRegionElbUrl));
assertTrue(target.isLimitlessDbShardGroupDns(usEastRegionLimitlessDbShardGroup));
assertFalse(target.isLimitlessDbShardGroupDns(euRedshift));

assertFalse(target.isLimitlessDbShardGroupDns(usIsobEastRegionCluster));
assertFalse(target.isLimitlessDbShardGroupDns(usIsobEastRegionClusterReadOnly));
Expand Down Expand Up @@ -412,6 +423,9 @@ public void testGetRdsRegion() {
assertEquals(chinaExpectedHostPattern, target.getRdsRegion(oldChinaRegionProxy));
assertEquals(chinaExpectedHostPattern, target.getRdsRegion(oldChinaRegionCustomDomain));
assertEquals(chinaExpectedHostPattern, target.getRdsRegion(oldChinaRegionLimitlessDbShardGroup));

final String euRedshiftExpectedHostPattern = "eusc-de-east-1";
assertEquals(euRedshiftExpectedHostPattern, target.getRdsRegion(euRedshift));
}

@Test
Expand Down
Loading