Skip to content

Commit 2e25357

Browse files
bereadyforoshai
authored andcommitted
support serverRSAPublicKeyFile configuration properties
- For property naming, please refer to MySQL Connector/J.
1 parent cfa7fa4 commit 2e25357

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

r2dbc-mysql/src/main/java/MysqlConnectionFactoryProvider.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import io.r2dbc.spi.ConnectionFactoryOptions.USER
1515
import io.r2dbc.spi.ConnectionFactoryProvider
1616
import io.r2dbc.spi.Option
1717
import mu.KotlinLogging
18+
import java.nio.file.Paths
1819
import java.time.Duration
1920
import kotlin.properties.ReadWriteProperty
2021
import kotlin.reflect.KProperty
@@ -30,6 +31,12 @@ class MysqlConnectionFactoryProvider : ConnectionFactoryProvider {
3031
@JvmField
3132
val APPLICATION_NAME: Option<String> = Option.valueOf("applicationName")
3233

34+
/**
35+
* Server rsa public key file.
36+
*/
37+
@JvmField
38+
val SERVER_RSA_PUBLIC_KEY_FILE: Option<String> = Option.valueOf("serverRSAPublicKeyFile")
39+
3340
/**
3441
* Driver option value.
3542
*/
@@ -72,7 +79,8 @@ class MysqlConnectionFactoryProvider : ConnectionFactoryProvider {
7279
applicationName = connectionFactoryOptions.getValue(APPLICATION_NAME) as String?,
7380
connectionTimeout = (connectionFactoryOptions.getValue(CONNECT_TIMEOUT) as Duration?)?.toMillis()?.toInt() ?: 5000,
7481
queryTimeout = connectionFactoryOptions.getValue(STATEMENT_TIMEOUT) as Duration?,
75-
ssl = MysqlSSLConfigurationFactory.create(connectionFactoryOptions)
82+
ssl = MysqlSSLConfigurationFactory.create(connectionFactoryOptions),
83+
rsaPublicKey = (connectionFactoryOptions.getValue(SERVER_RSA_PUBLIC_KEY_FILE) as String?)?.let { Paths.get(it) }
7684
)
7785
return JasyncConnectionFactory(MySQLConnectionFactory(configuration))
7886
}

r2dbc-mysql/src/test/java/com/github/jasync/r2dbc/mysql/MysqlConnectionFactoryProviderTest.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,26 @@ class MysqlConnectionFactoryProviderTest {
4141
// then
4242
assertEquals(3307, result.mySQLConnectionFactory.configuration.port)
4343
}
44+
45+
@Test
46+
fun shouldNotUseWhenRsaPublicKeyIsNotSpecified() {
47+
val options = ConnectionFactoryOptions.parse("r2dbc:mysql://user@host/")
48+
49+
// when
50+
val result = provider.create(options)
51+
52+
// then
53+
assertEquals(null, result.mySQLConnectionFactory.configuration.rsaPublicKey)
54+
}
55+
56+
@Test
57+
fun shouldUseSpecifiedRsaPublicKey() {
58+
val options = ConnectionFactoryOptions.parse("r2dbc:mysql://user@host/db?serverRSAPublicKeyFile=rsa.pem")
59+
60+
// when
61+
val result = provider.create(options)
62+
63+
// then
64+
assertEquals("rsa.pem", result.mySQLConnectionFactory.configuration.rsaPublicKey.toString())
65+
}
4466
}

0 commit comments

Comments
 (0)