Skip to content

Commit ad6a7cb

Browse files
Feat(mysql-event-listener): Add user and password config to MySQL event listener
Allow configuring MySQL credentials for the event listener using separate mysql-event-listener.db.user and mysql-event-listener.db.password properties. This makes it easier and safer to provide credentials, especially when passwords contain special characters, and aligns with the configuration style of other Trino connectors. The connection logic now uses these properties if provided, falling back to credentials in the JDBC URL if not set.
1 parent fd2b5a2 commit ad6a7cb

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

docs/src/main/sphinx/admin/event-listeners-mysql.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,12 @@ string, user, catalog, and others with information about the query processing.
6666
* - Property name
6767
- Description
6868
* - `mysql-event-listener.db.url`
69-
- JDBC connection URL to the database including credentials
69+
- Fully qualified JDBC connection URL used to connect to the MySQL database.
70+
Credentials can be embedded in the URL if `user` and `password` are not specified separately
71+
* - `mysql-event-listener.db.user`
72+
- Username used for authenticating the JDBC connection to the MySQL database.
73+
Ignored if credentials are included in the `URL`
74+
* - `mysql-event-listener.db.password`
75+
- Password used for authenticating the JDBC connection to the MySQL database.
76+
Ignored if credentials are included in the `URL`
7077
:::

plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/MysqlEventListenerConfig.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,41 @@
2424
public class MysqlEventListenerConfig
2525
{
2626
private String url;
27+
private String user;
28+
private String password;
2729

2830
@NotNull
2931
public String getUrl()
3032
{
3133
return url;
3234
}
3335

36+
public String getUser()
37+
{
38+
return user;
39+
}
40+
41+
@ConfigSecuritySensitive
42+
@Config("mysql-event-listener.db.user")
43+
public MysqlEventListenerConfig setUser(String user)
44+
{
45+
this.user = user;
46+
return this;
47+
}
48+
49+
public String getPassword()
50+
{
51+
return password;
52+
}
53+
54+
@ConfigSecuritySensitive
55+
@Config("mysql-event-listener.db.password")
56+
public MysqlEventListenerConfig setPassword(String password)
57+
{
58+
this.password = password;
59+
return this;
60+
}
61+
3462
@ConfigSecuritySensitive
3563
@Config("mysql-event-listener.db.url")
3664
public MysqlEventListenerConfig setUrl(String url)

plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/MysqlEventListenerFactory.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,16 @@ public void configure(Binder binder)
9090
@Provides
9191
public ConnectionFactory createConnectionFactory(MysqlEventListenerConfig config)
9292
{
93-
return () -> new Driver().connect(config.getUrl(), new Properties());
93+
return () -> {
94+
Properties properties = new Properties();
95+
if (config.getUser() != null) {
96+
properties.setProperty("user", config.getUser());
97+
}
98+
if (config.getPassword() != null) {
99+
properties.setProperty("password", config.getPassword());
100+
}
101+
return new Driver().connect(config.getUrl(), properties);
102+
};
94103
}
95104

96105
@Singleton

plugin/trino-mysql-event-listener/src/test/java/io/trino/plugin/eventlistener/mysql/TestMysqlEventListenerConfig.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,23 @@ final class TestMysqlEventListenerConfig
2828
void testDefaults()
2929
{
3030
assertRecordedDefaults(recordDefaults(MysqlEventListenerConfig.class)
31-
.setUrl(null));
31+
.setUrl(null)
32+
.setUser(null)
33+
.setPassword(null));
3234
}
3335

3436
@Test
3537
void testExplicitPropertyMappings()
3638
{
3739
Map<String, String> properties = Map.of(
38-
"mysql-event-listener.db.url", "jdbc:mysql://example.net:3306");
40+
"mysql-event-listener.db.url", "jdbc:mysql://example.net:3306",
41+
"mysql-event-listener.db.user", "user",
42+
"mysql-event-listener.db.password", "password");
3943

4044
MysqlEventListenerConfig expected = new MysqlEventListenerConfig()
41-
.setUrl("jdbc:mysql://example.net:3306");
45+
.setUrl("jdbc:mysql://example.net:3306")
46+
.setUser("user")
47+
.setPassword("password");
4248

4349
assertFullMapping(properties, expected);
4450
}

0 commit comments

Comments
 (0)