Replace unixSocketPath with ipTypes for Cloud SQL TCP#402
Conversation
…CP connection Switch Cloud SQL connector from Unix socket to TCP+TLS by removing unixSocketPath and setting ipTypes=PUBLIC,PRIVATE, allowing the Java connector to establish direct connections without a proxy sidecar. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…ocketPath Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the Cloud SQL database configuration to use TCP connections instead of Unix sockets by replacing the unixSocketPath property with ipTypes set to "PUBLIC,PRIVATE". This enables TCP-based connections to Cloud SQL instances while maintaining support for both public and private IP types. The change is applied consistently to both the Java (Spring Boot) and Kotlin (Ktor) implementations of the lamp control API.
Changes:
- Java implementation: Modified
DataSourceConfig.javato useipTypesinstead ofunixSocketPathfor Cloud SQL connections - Kotlin implementation: Modified
DatabaseFactory.ktto useipTypesinstead ofunixSocketPathfor Cloud SQL connections
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/java/src/main/java/org/openapitools/config/DataSourceConfig.java | Replaced unixSocketPath data source property with ipTypes property in Cloud SQL configuration |
| src/kotlin/src/main/kotlin/com/lampcontrol/database/DatabaseFactory.kt | Replaced unixSocketPath data source property with ipTypes property in Cloud SQL configuration |
|
|
||
| config.addDataSourceProperty("socketFactory", "com.google.cloud.sql.postgres.SocketFactory"); | ||
| config.addDataSourceProperty("unixSocketPath", instanceUnixSocket); | ||
| config.addDataSourceProperty("ipTypes", "PUBLIC,PRIVATE"); |
There was a problem hiding this comment.
The variable instanceUnixSocket (line 202) is still being used but is now misleading since the code uses TCP connections with ipTypes instead of Unix sockets. The variable should be renamed to reflect its current purpose of identifying the Cloud SQL instance path. Additionally, this change from unixSocketPath to ipTypes will break existing tests in DataSourceConfigTest.java (lines 97 and 123) that assert the presence of unixSocketPath in data source properties. The tests need to be updated to check for ipTypes with value "PUBLIC,PRIVATE" instead.
|
|
||
| hikariConfig.addDataSourceProperty("socketFactory", CLOUD_SQL_SOCKET_FACTORY) | ||
| hikariConfig.addDataSourceProperty("unixSocketPath", config.host) | ||
| hikariConfig.addDataSourceProperty("ipTypes", "PUBLIC,PRIVATE") |
There was a problem hiding this comment.
The parameter name unixSocketPath in the extractCloudSqlInstance function (line 91) is misleading after this change. Since the code now uses TCP connections with ipTypes instead of Unix sockets, this parameter should be renamed to something more accurate like cloudSqlHostPath or instancePath to reflect that it contains the Cloud SQL instance identifier path. Additionally, this change will break the test in DatabaseFactoryTest.kt (line 70) that asserts the presence of unixSocketPath in data source properties. The test needs to be updated to check for ipTypes with value "PUBLIC,PRIVATE" instead.
| config.addDataSourceProperty("socketFactory", "com.google.cloud.sql.postgres.SocketFactory"); | ||
| config.addDataSourceProperty("unixSocketPath", instanceUnixSocket); | ||
| config.addDataSourceProperty("ipTypes", "PUBLIC,PRIVATE"); | ||
| String cloudSqlInstance = extractCloudSqlInstance(instanceUnixSocket); |
There was a problem hiding this comment.
After switching from unixSocketPath to ipTypes for TCP connections, the variable name instanceUnixSocket at line 209 is misleading. While the logic correctly extracts the Cloud SQL instance identifier from the path, the variable name suggests Unix socket usage. Consider renaming to instancePath or cloudSqlHostPath to better reflect its purpose of identifying the Cloud SQL instance regardless of connection type.
Changes
Update Cloud SQL configuration to use TCP connections instead of Unix sockets:
unixSocketPathwithipTypesproperty set to"PUBLIC,PRIVATE"inDataSourceConfig.javaunixSocketPathwithipTypesproperty set to"PUBLIC,PRIVATE"inDatabaseFactory.ktThis change enables TCP-based connections to Cloud SQL instances while maintaining support for both public and private IP types.