Skip to content

[r2dbc-mysql] support serverRSAPublicKeyFile configuration properties #398

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

Merged
merged 1 commit into from
Jun 15, 2023
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
10 changes: 9 additions & 1 deletion r2dbc-mysql/src/main/java/MysqlConnectionFactoryProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import io.r2dbc.spi.ConnectionFactoryOptions.USER
import io.r2dbc.spi.ConnectionFactoryProvider
import io.r2dbc.spi.Option
import mu.KotlinLogging
import java.nio.file.Paths
import java.time.Duration
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
Expand All @@ -30,6 +31,12 @@ class MysqlConnectionFactoryProvider : ConnectionFactoryProvider {
@JvmField
val APPLICATION_NAME: Option<String> = Option.valueOf("applicationName")

/**
* Server rsa public key file.
*/
@JvmField
val SERVER_RSA_PUBLIC_KEY_FILE: Option<String> = Option.valueOf("serverRSAPublicKeyFile")

/**
* Driver option value.
*/
Expand Down Expand Up @@ -72,7 +79,8 @@ class MysqlConnectionFactoryProvider : ConnectionFactoryProvider {
applicationName = connectionFactoryOptions.getValue(APPLICATION_NAME) as String?,
connectionTimeout = (connectionFactoryOptions.getValue(CONNECT_TIMEOUT) as Duration?)?.toMillis()?.toInt() ?: 5000,
queryTimeout = connectionFactoryOptions.getValue(STATEMENT_TIMEOUT) as Duration?,
ssl = MysqlSSLConfigurationFactory.create(connectionFactoryOptions)
ssl = MysqlSSLConfigurationFactory.create(connectionFactoryOptions),
rsaPublicKey = (connectionFactoryOptions.getValue(SERVER_RSA_PUBLIC_KEY_FILE) as String?)?.let { Paths.get(it) }
)
return JasyncConnectionFactory(MySQLConnectionFactory(configuration))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,26 @@ class MysqlConnectionFactoryProviderTest {
// then
assertEquals(3307, result.mySQLConnectionFactory.configuration.port)
}

@Test
fun shouldNotUseWhenRsaPublicKeyIsNotSpecified() {
val options = ConnectionFactoryOptions.parse("r2dbc:mysql://user@host/")

// when
val result = provider.create(options)

// then
assertEquals(null, result.mySQLConnectionFactory.configuration.rsaPublicKey)
}

@Test
fun shouldUseSpecifiedRsaPublicKey() {
val options = ConnectionFactoryOptions.parse("r2dbc:mysql://user@host/db?serverRSAPublicKeyFile=rsa.pem")

// when
val result = provider.create(options)

// then
assertEquals("rsa.pem", result.mySQLConnectionFactory.configuration.rsaPublicKey.toString())
}
}