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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/#semantic-versioning-200).

## [?]

### :magic_wand: Added
- Elastic Load Balancer URL support ([PR#476](https://github.com/awslabs/aws-advanced-jdbc-wrapper/pull/476)).

### :bug: Fixed
- Values for the `wrapperLoggerLevel` parameter are no longer case-sensitive ([#PR #481](https://github.com/awslabs/aws-advanced-jdbc-wrapper/pull/481)).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ IAM database authentication use is limited to certain database engines. For more
|-------------------|:-------:|:--------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|
| `wrapperPlugins` | String | No | Set to `"iam"` to enable AWS IAM database authentication | `iam` |
| `iamDefaultPort` | String | No | This property will override the default port that is used to generate the IAM token. The default port is determined based on the underlying driver protocol. For now, there is support for `jdbc:postgresql:` and `jdbc:mysql:`. Target drivers with different protocols will require users to provide a default port. | `1234` |
| `iamHost` | String | No | This property will override the default hostname that is used to generate the IAM token. The default hostname is derived from the connection string. This parameter is useful when users are connecting with custom endpoints. | `database.cluster-hash.us-east-1.rds.amazonaws.com` |
| `iamHost` | String | No | This property will override the default hostname that is used to generate the IAM token. The default hostname is derived from the connection string. This parameter is required when users are connecting with custom endpoints. | `database.cluster-hash.us-east-1.rds.amazonaws.com` |
| `iamRegion` | String | No | This property will override the default region that is used to generate the IAM token. The default region is parsed from the connection string. | `us-east-2` |
| `iamExpiration` | Integer | No | This property will override the default expiration time that is assigned to the generated IAM token. The default expiration time is set to be 15 minutes. | `600` |

Expand Down
16 changes: 16 additions & 0 deletions wrapper/src/main/java/software/amazon/jdbc/util/RdsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ public class RdsUtils {
+ "(?<domain>[a-zA-Z0-9]+\\.rds\\.(?<region>[a-zA-Z0-9\\-])+\\.amazonaws\\.com\\.cn)",
Pattern.CASE_INSENSITIVE);

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

private static final Pattern IP_V4 =
Pattern.compile(
"^(([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){1}"
Expand Down Expand Up @@ -167,6 +173,11 @@ public boolean isRdsProxyDns(final String host) {
return AURORA_PROXY_DNS_PATTERN.matcher(host).find() || AURORA_CHINA_PROXY_DNS_PATTERN.matcher(host).find();
}

public boolean isElbUrl(final String host) {
return !StringUtils.isNullOrEmpty(host)
&& (ELB_PATTERN.matcher(host).find());
}

public String getRdsInstanceHostPattern(final String host) {
if (StringUtils.isNullOrEmpty(host)) {
return "?";
Expand Down Expand Up @@ -196,6 +207,10 @@ public String getRdsRegion(final String host) {
if (chinaMatcher.find()) {
return chinaMatcher.group(REGION_GROUP);
}
final Matcher elbMatcher = ELB_PATTERN.matcher(host);
if (elbMatcher.find()) {
return elbMatcher.group(REGION_GROUP);
}
return null;
}

Expand Down Expand Up @@ -277,6 +292,7 @@ public RdsUrlType identifyRdsType(final String host) {
} else if (isRdsDns(host)) {
return RdsUrlType.RDS_INSTANCE;
} else {
// ELB URLs will also be classified as other
return RdsUrlType.OTHER;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class RdsUtilsTests {
private static final String chinaRegionCustomDomain =
"custom-test-name.cluster-custom-XYZ.rds.cn-northwest-1.amazonaws.com.cn";

private static final String usEastRegionElbUrl =
"elb-name.elb.us-east-2.amazonaws.com";

@Test
public void testIsRdsDns() {
RdsUtils target = new RdsUtils();
Expand All @@ -55,6 +58,7 @@ public void testIsRdsDns() {
assertTrue(target.isRdsDns(usEastRegionInstance));
assertTrue(target.isRdsDns(usEastRegionProxy));
assertTrue(target.isRdsDns(usEastRegionCustomDomain));
assertFalse(target.isRdsDns(usEastRegionElbUrl));

assertTrue(target.isRdsDns(chinaRegionCluster));
assertTrue(target.isRdsDns(chinaRegionClusterReadOnly));
Expand Down Expand Up @@ -91,6 +95,7 @@ public void testIsRdsClusterDns() {
assertFalse(target.isRdsClusterDns(usEastRegionInstance));
assertFalse(target.isRdsClusterDns(usEastRegionProxy));
assertFalse(target.isRdsClusterDns(usEastRegionCustomDomain));
assertFalse(target.isRdsClusterDns(usEastRegionElbUrl));

assertTrue(target.isRdsClusterDns(chinaRegionCluster));
assertTrue(target.isRdsClusterDns(chinaRegionClusterReadOnly));
Expand All @@ -108,6 +113,7 @@ public void testIsWriterClusterDns() {
assertFalse(target.isWriterClusterDns(usEastRegionInstance));
assertFalse(target.isWriterClusterDns(usEastRegionProxy));
assertFalse(target.isWriterClusterDns(usEastRegionCustomDomain));
assertFalse(target.isWriterClusterDns(usEastRegionElbUrl));

assertTrue(target.isWriterClusterDns(chinaRegionCluster));
assertFalse(target.isWriterClusterDns(chinaRegionClusterReadOnly));
Expand All @@ -125,6 +131,7 @@ public void testIsReaderClusterDns() {
assertFalse(target.isReaderClusterDns(usEastRegionInstance));
assertFalse(target.isReaderClusterDns(usEastRegionProxy));
assertFalse(target.isReaderClusterDns(usEastRegionCustomDomain));
assertFalse(target.isReaderClusterDns(usEastRegionElbUrl));

assertFalse(target.isReaderClusterDns(chinaRegionCluster));
assertTrue(target.isReaderClusterDns(chinaRegionClusterReadOnly));
Expand All @@ -143,6 +150,7 @@ public void testGetRdsRegion() {
assertEquals(expectedHostPattern, target.getRdsRegion(usEastRegionInstance));
assertEquals(expectedHostPattern, target.getRdsRegion(usEastRegionProxy));
assertEquals(expectedHostPattern, target.getRdsRegion(usEastRegionCustomDomain));
assertEquals(expectedHostPattern, target.getRdsRegion(usEastRegionElbUrl));

final String chinaExpectedHostPattern = "cn-northwest-1";
assertEquals(chinaExpectedHostPattern, target.getRdsRegion(chinaRegionCluster));
Expand Down