-
Notifications
You must be signed in to change notification settings - Fork 315
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
feat: Add all additional Cloud SQL Java Connector parameters #3286
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,10 @@ | |
|
||
package com.google.cloud.spring.autoconfigure.sql; | ||
|
||
import java.net.URLEncoder; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import org.springframework.util.Assert; | ||
import org.springframework.util.StringUtils; | ||
|
||
|
@@ -54,12 +58,49 @@ public String getJdbcUrl() { | |
this.properties.getDatabaseName(), | ||
this.properties.getInstanceConnectionName()); | ||
|
||
// Build additional JDBC url parameters from the configuration. | ||
Map<String, String> urlParams = new LinkedHashMap<>(); | ||
if (StringUtils.hasText(properties.getIpTypes())) { | ||
jdbcUrl += "&ipTypes=" + properties.getIpTypes(); | ||
urlParams.put("ipTypes", properties.getIpTypes()); | ||
} | ||
|
||
if (properties.isEnableIamAuth()) { | ||
jdbcUrl += "&enableIamAuth=true&sslmode=disable"; | ||
urlParams.put("enableIamAuth", "true"); | ||
urlParams.put("sslmode", "disable"); | ||
} | ||
if (StringUtils.hasText(properties.getTargetPrincipal())) { | ||
urlParams.put("cloudSqlTargetPrincipal", properties.getTargetPrincipal()); | ||
} | ||
if (StringUtils.hasText(properties.getDelegates())) { | ||
urlParams.put("cloudSqlDelegates", properties.getDelegates()); | ||
} | ||
if (StringUtils.hasText(properties.getAdminRootUrl())) { | ||
urlParams.put("cloudSqlAdminRootUrl", properties.getAdminRootUrl()); | ||
} | ||
if (StringUtils.hasText(properties.getAdminServicePath())) { | ||
urlParams.put("cloudSqlAdminServicePath", properties.getAdminServicePath()); | ||
} | ||
if (StringUtils.hasText(properties.getAdminQuotaProject())) { | ||
urlParams.put("cloudSqlAdminQuotaProject", properties.getAdminQuotaProject()); | ||
} | ||
if (StringUtils.hasText(properties.getUniverseDomain())) { | ||
urlParams.put("cloudSqlUniverseDomain", properties.getUniverseDomain()); | ||
mpeddada1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if (StringUtils.hasText(properties.getRefreshStrategy())) { | ||
urlParams.put("cloudSqlRefreshStrategy", properties.getRefreshStrategy()); | ||
} | ||
|
||
// Convert map to a string of url parameters | ||
String urlParamsString = | ||
urlParams.entrySet().stream() | ||
.map( | ||
entry -> | ||
URLEncoder.encode(entry.getKey()) + "=" + URLEncoder.encode(entry.getValue())) | ||
.collect(Collectors.joining("&")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add at least one test that verifies the output of this logic? This would protect against future modifications. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @burkedavison , would a test like the one in #3286 (comment) be enough? |
||
|
||
// Append url parameters to the JDBC URL. | ||
if (StringUtils.hasText(urlParamsString)) { | ||
jdbcUrl = jdbcUrl + "&" + urlParamsString; | ||
} | ||
|
||
return jdbcUrl; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also add testing for these new properties in
spring-cloud-gcp/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/sql/CloudSqlEnvironmentPostProcessorTests.java
Line 41 in f5879d9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test method should do the trick:
I tried to create a PR to the existing PR, but I have no clue about your formatting rules (spotless?)
@hessjcg , maybe you accept this "PR" by just copy the code 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I tried with #3313 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @mieseprem for the test! I have moved it code into this PR.