Skip to content

Commit 423ebd9

Browse files
committed
Add MySQL ssl option
1 parent 1f10077 commit 423ebd9

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

embulk-output-mysql/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ MySQL output plugin for Embulk loads records to MySQL.
1414
- **port**: database port number (integer, default: 3306)
1515
- **user**: database login user name (string, required)
1616
- **password**: database login password (string, default: "")
17+
- **ssl**: use SSL to connect to the database (string, default: `disable`. `enable` uses SSL without server-side validation and `verify` checks the certificate. For compatibility reasons, `true` behaves as `enable` and `false` behaves as `disable`.)
1718
- **database**: destination database name (string, required)
1819
- **temp_database**: database name for intermediate tables. by default, intermediate tables will be created in the database specified by `database`. (string, optional)
1920
- **table**: destination table name (string, required)

embulk-output-mysql/src/main/java/org/embulk/output/MySQLOutputPlugin.java

+21-15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.embulk.config.Config;
1010
import org.embulk.config.ConfigDefault;
1111
import org.embulk.output.jdbc.AbstractJdbcOutputPlugin;
12+
import org.embulk.output.jdbc.Ssl;
1213
import org.embulk.output.jdbc.BatchInsert;
1314
import org.embulk.output.jdbc.JdbcOutputConnection;
1415
import org.embulk.output.jdbc.MergeConfig;
@@ -44,6 +45,11 @@ public interface MySQLPluginTask
4445
@Config("temp_database")
4546
@ConfigDefault("null")
4647
public Optional<String> getTempDatabase();
48+
49+
@Config("ssl")
50+
@ConfigDefault("\"disable\"") // backward compatibility
51+
public Ssl getSsl();
52+
4753
}
4854

4955
@Override
@@ -80,21 +86,21 @@ protected MySQLOutputConnector getConnector(PluginTask task, boolean retryableMe
8086
// Socket options TCP_KEEPCNT, TCP_KEEPIDLE, and TCP_KEEPINTVL are not configurable.
8187
props.setProperty("tcpKeepAlive", "true");
8288

83-
// TODO
84-
//switch t.getSssl() {
85-
//when "disable":
86-
// break;
87-
//when "enable":
88-
// props.setProperty("useSSL", "true");
89-
// props.setProperty("requireSSL", "false");
90-
// props.setProperty("verifyServerCertificate", "false");
91-
// break;
92-
//when "verify":
93-
// props.setProperty("useSSL", "true");
94-
// props.setProperty("requireSSL", "true");
95-
// props.setProperty("verifyServerCertificate", "true");
96-
// break;
97-
//}
89+
switch (t.getSsl()) {
90+
case DISABLE:
91+
props.setProperty("useSSL", "false");
92+
break;
93+
case ENABLE:
94+
props.setProperty("useSSL", "true");
95+
props.setProperty("requireSSL", "true");
96+
props.setProperty("verifyServerCertificate", "false");
97+
break;
98+
case VERIFY:
99+
props.setProperty("useSSL", "true");
100+
props.setProperty("requireSSL", "true");
101+
props.setProperty("verifyServerCertificate", "true");
102+
break;
103+
}
98104

99105
if (!retryableMetadataOperation) {
100106
// non-retryable batch operation uses longer timeout

0 commit comments

Comments
 (0)