-
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
Conversation
14c58f5
to
a82e856
Compare
...src/main/java/com/google/cloud/spring/autoconfigure/sql/DefaultCloudSqlJdbcInfoProvider.java
Show resolved
Hide resolved
@@ -54,12 +58,49 @@ public String getJdbcUrl() { | |||
this.properties.getDatabaseName(), | |||
this.properties.getInstanceConnectionName()); | |||
|
|||
// Build additional JDBC url parameters from the configuration. |
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
Line 41 in f5879d9
class CloudSqlEnvironmentPostProcessorTests { |
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:
@Test
void testCloudSqlSpringDatasourceWithAllOptions() {
this.contextRunner
.withPropertyValues(
"spring.cloud.gcp.sql.admin-quota-project=someAdminQuotaProjectValue",
"spring.cloud.gcp.sql.admin-root-url=someAdminRootUrlValue",
"spring.cloud.gcp.sql.admin-service-path=someAdminServicePathValue",
"spring.cloud.gcp.sql.database-name=test-database",
"spring.cloud.gcp.sql.delegates=delegate1,delegate2",
"spring.cloud.gcp.sql.enable-iam-auth=true",
"spring.cloud.gcp.sql.instance-connection-name=tubular-bells:singapore:test-instance",
"spring.cloud.gcp.sql.ip-types=PRIVATE",
"spring.cloud.gcp.sql.refresh-strategy=lazy",
"spring.cloud.gcp.sql.target-principal=target-principal",
"spring.cloud.gcp.sql.universe-domain=someUniverseDomainValue",
"spring.datasource.username=foo",
"spring.datasource.password=bar")
.run(
context -> {
HikariDataSource dataSource = (HikariDataSource) context.getBean(DataSource.class);
assertThat(dataSource)
.returns("com.mysql.cj.jdbc.Driver", HikariDataSource::getDriverClassName)
.returns("foo", HikariDataSource::getUsername)
.returns("bar", HikariDataSource::getPassword)
.extracting(HikariDataSource::getJdbcUrl)
.asInstanceOf(InstanceOfAssertFactories.STRING)
.startsWith("jdbc:mysql://google/test-database?"
+ "socketFactory=com.google.cloud.sql.mysql.SocketFactory")
.satisfies(
jdbcUrl -> assertThat(jdbcUrl.substring(jdbcUrl.indexOf('&') + 1).split("&"))
.containsExactlyInAnyOrder(
"cloudSqlAdminQuotaProject=someAdminQuotaProjectValue",
"cloudSqlAdminRootUrl=someAdminRootUrlValue",
"cloudSqlAdminServicePath=someAdminServicePathValue",
"cloudSqlDelegates=delegate1%2Cdelegate2",
"cloudSqlInstance=tubular-bells:singapore:test-instance",
"cloudSqlRefreshStrategy=lazy",
"cloudSqlTargetPrincipal=target-principal",
"cloudSqlUniverseDomain=someUniverseDomainValue",
"enableIamAuth=true",
"ipTypes=PRIVATE",
"sslmode=disable"));
assertThat(getSpringDatasourceDriverClassName(context))
.matches("com.mysql.cj.jdbc.Driver");
});
}
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.
.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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
@burkedavison , would a test like the one in #3286 (comment) be enough?
…pring configuration. This adds JDBC needed for lazy refresh, service account impersonation, universe domains, and alternate SQL Admin API endpoints to the JDBC configuration for a Cloud SQL JDBC connection. This is related to GoogleCloudPlatform/cloud-sql-jdbc-socket-factory#2065.
a82e856
to
68ebfa4
Compare
Quality Gate failedFailed conditions |
This adds JDBC properties needed for lazy refresh, service account impersonation, universe domains, and alternate
SQL Admin API endpoints to the JDBC configuration for a Cloud SQL JDBC connection.
See #3285
This is related to GoogleCloudPlatform/cloud-sql-jdbc-socket-factory#2065.