Skip to content

Commit 019a008

Browse files
feat: ELB URL support (#476)
1 parent bc383da commit 019a008

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
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).
55

66
## [?]
7+
8+
### :magic_wand: Added
9+
- Elastic Load Balancer URL support ([PR#476](https://github.com/awslabs/aws-advanced-jdbc-wrapper/pull/476)).
10+
711
### :bug: Fixed
812
- Values for the `wrapperLoggerLevel` parameter are no longer case-sensitive ([#PR #481](https://github.com/awslabs/aws-advanced-jdbc-wrapper/pull/481)).
913

docs/using-the-jdbc-driver/using-plugins/UsingTheIamAuthenticationPlugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ IAM database authentication use is limited to certain database engines. For more
2828
|-------------------|:-------:|:--------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|
2929
| `wrapperPlugins` | String | No | Set to `"iam"` to enable AWS IAM database authentication | `iam` |
3030
| `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` |
31-
| `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` |
31+
| `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` |
3232
| `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` |
3333
| `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` |
3434

wrapper/src/main/java/software/amazon/jdbc/util/RdsUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ public class RdsUtils {
125125
+ "(?<domain>[a-zA-Z0-9]+\\.rds\\.(?<region>[a-zA-Z0-9\\-])+\\.amazonaws\\.com\\.cn)",
126126
Pattern.CASE_INSENSITIVE);
127127

128+
private static final Pattern ELB_PATTERN =
129+
Pattern.compile(
130+
"(?<instance>.+)\\.elb\\."
131+
+ "((?<region>[a-zA-Z0-9\\-]+)\\.amazonaws\\.com)",
132+
Pattern.CASE_INSENSITIVE);
133+
128134
private static final Pattern IP_V4 =
129135
Pattern.compile(
130136
"^(([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){1}"
@@ -167,6 +173,11 @@ public boolean isRdsProxyDns(final String host) {
167173
return AURORA_PROXY_DNS_PATTERN.matcher(host).find() || AURORA_CHINA_PROXY_DNS_PATTERN.matcher(host).find();
168174
}
169175

176+
public boolean isElbUrl(final String host) {
177+
return !StringUtils.isNullOrEmpty(host)
178+
&& (ELB_PATTERN.matcher(host).find());
179+
}
180+
170181
public String getRdsInstanceHostPattern(final String host) {
171182
if (StringUtils.isNullOrEmpty(host)) {
172183
return "?";
@@ -196,6 +207,10 @@ public String getRdsRegion(final String host) {
196207
if (chinaMatcher.find()) {
197208
return chinaMatcher.group(REGION_GROUP);
198209
}
210+
final Matcher elbMatcher = ELB_PATTERN.matcher(host);
211+
if (elbMatcher.find()) {
212+
return elbMatcher.group(REGION_GROUP);
213+
}
199214
return null;
200215
}
201216

@@ -277,6 +292,7 @@ public RdsUrlType identifyRdsType(final String host) {
277292
} else if (isRdsDns(host)) {
278293
return RdsUrlType.RDS_INSTANCE;
279294
} else {
295+
// ELB URLs will also be classified as other
280296
return RdsUrlType.OTHER;
281297
}
282298
}

wrapper/src/test/java/software/amazon/jdbc/util/RdsUtilsTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public class RdsUtilsTests {
4646
private static final String chinaRegionCustomDomain =
4747
"custom-test-name.cluster-custom-XYZ.rds.cn-northwest-1.amazonaws.com.cn";
4848

49+
private static final String usEastRegionElbUrl =
50+
"elb-name.elb.us-east-2.amazonaws.com";
51+
4952
@Test
5053
public void testIsRdsDns() {
5154
RdsUtils target = new RdsUtils();
@@ -55,6 +58,7 @@ public void testIsRdsDns() {
5558
assertTrue(target.isRdsDns(usEastRegionInstance));
5659
assertTrue(target.isRdsDns(usEastRegionProxy));
5760
assertTrue(target.isRdsDns(usEastRegionCustomDomain));
61+
assertFalse(target.isRdsDns(usEastRegionElbUrl));
5862

5963
assertTrue(target.isRdsDns(chinaRegionCluster));
6064
assertTrue(target.isRdsDns(chinaRegionClusterReadOnly));
@@ -91,6 +95,7 @@ public void testIsRdsClusterDns() {
9195
assertFalse(target.isRdsClusterDns(usEastRegionInstance));
9296
assertFalse(target.isRdsClusterDns(usEastRegionProxy));
9397
assertFalse(target.isRdsClusterDns(usEastRegionCustomDomain));
98+
assertFalse(target.isRdsClusterDns(usEastRegionElbUrl));
9499

95100
assertTrue(target.isRdsClusterDns(chinaRegionCluster));
96101
assertTrue(target.isRdsClusterDns(chinaRegionClusterReadOnly));
@@ -108,6 +113,7 @@ public void testIsWriterClusterDns() {
108113
assertFalse(target.isWriterClusterDns(usEastRegionInstance));
109114
assertFalse(target.isWriterClusterDns(usEastRegionProxy));
110115
assertFalse(target.isWriterClusterDns(usEastRegionCustomDomain));
116+
assertFalse(target.isWriterClusterDns(usEastRegionElbUrl));
111117

112118
assertTrue(target.isWriterClusterDns(chinaRegionCluster));
113119
assertFalse(target.isWriterClusterDns(chinaRegionClusterReadOnly));
@@ -125,6 +131,7 @@ public void testIsReaderClusterDns() {
125131
assertFalse(target.isReaderClusterDns(usEastRegionInstance));
126132
assertFalse(target.isReaderClusterDns(usEastRegionProxy));
127133
assertFalse(target.isReaderClusterDns(usEastRegionCustomDomain));
134+
assertFalse(target.isReaderClusterDns(usEastRegionElbUrl));
128135

129136
assertFalse(target.isReaderClusterDns(chinaRegionCluster));
130137
assertTrue(target.isReaderClusterDns(chinaRegionClusterReadOnly));
@@ -143,6 +150,7 @@ public void testGetRdsRegion() {
143150
assertEquals(expectedHostPattern, target.getRdsRegion(usEastRegionInstance));
144151
assertEquals(expectedHostPattern, target.getRdsRegion(usEastRegionProxy));
145152
assertEquals(expectedHostPattern, target.getRdsRegion(usEastRegionCustomDomain));
153+
assertEquals(expectedHostPattern, target.getRdsRegion(usEastRegionElbUrl));
146154

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

0 commit comments

Comments
 (0)