Skip to content

Commit 491a054

Browse files
authored
Merge pull request #109 from hiroyuki-sato/add_mysql_ssl_option
Add mysql ssl option
2 parents 2432e3e + 19e9fa7 commit 491a054

File tree

3 files changed

+58
-15
lines changed

3 files changed

+58
-15
lines changed

embulk-input-jdbc/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Generic JDBC input plugin for Embulk loads records from a database using a JDBC
1414
- **url**: URL of the JDBC connection (e.g. 'jdbc:sqlite:mydb.sqlite3') (string, required)
1515
- **user**: database login user name (string, optional)
1616
- **password**: database login password (string, default: optional)
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
- **schema**: destination schema name (string, default: use the default schema)
1819
- **fetch_rows**: number of rows to fetch one time (integer, default: 10000)
1920
- **connect_timeout**: not supported.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.embulk.input.jdbc;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonValue;
5+
6+
import org.embulk.config.ConfigException;
7+
8+
public enum Ssl
9+
{
10+
ENABLE,
11+
DISABLE,
12+
VERIFY;
13+
14+
@JsonValue
15+
@Override
16+
public String toString()
17+
{
18+
return this.name().toLowerCase();
19+
}
20+
21+
@JsonCreator
22+
public static Ssl fromString(String value)
23+
{
24+
switch(value) {
25+
case "enable":
26+
case "true":
27+
return ENABLE;
28+
case "disable":
29+
case "false":
30+
return DISABLE;
31+
case "verify":
32+
return VERIFY;
33+
default:
34+
throw new ConfigException(String.format("Unknown SSL value '%s'. Supported values are enable, true, disable, false or verify.", value));
35+
}
36+
}
37+
}

embulk-input-mysql/src/main/java/org/embulk/input/MySQLInputPlugin.java

+20-15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.embulk.config.Config;
1313
import org.embulk.config.ConfigDefault;
1414
import org.embulk.input.jdbc.AbstractJdbcInputPlugin;
15+
import org.embulk.input.jdbc.Ssl;
1516
import org.embulk.input.jdbc.JdbcInputConnection;
1617
import org.embulk.input.jdbc.getter.ColumnGetterFactory;
1718
import org.embulk.input.mysql.MySQLInputConnection;
@@ -42,6 +43,10 @@ public interface MySQLPluginTask
4243

4344
@Config("database")
4445
public String getDatabase();
46+
47+
@Config("ssl")
48+
@ConfigDefault("\"disable\"") // backward compatibility
49+
public Ssl getSsl();
4550
}
4651

4752
@Override
@@ -75,21 +80,21 @@ protected MySQLInputConnection newConnection(PluginTask task) throws SQLExceptio
7580
// Socket options TCP_KEEPCNT, TCP_KEEPIDLE, and TCP_KEEPINTVL are not configurable.
7681
props.setProperty("tcpKeepAlive", "true");
7782

78-
// TODO
79-
//switch task.getSssl() {
80-
//when "disable":
81-
// break;
82-
//when "enable":
83-
// props.setProperty("useSSL", "true");
84-
// props.setProperty("requireSSL", "false");
85-
// props.setProperty("verifyServerCertificate", "false");
86-
// break;
87-
//when "verify":
88-
// props.setProperty("useSSL", "true");
89-
// props.setProperty("requireSSL", "true");
90-
// props.setProperty("verifyServerCertificate", "true");
91-
// break;
92-
//}
83+
switch (t.getSsl()) {
84+
case DISABLE:
85+
props.setProperty("useSSL", "false");
86+
break;
87+
case ENABLE:
88+
props.setProperty("useSSL", "true");
89+
props.setProperty("requireSSL", "true");
90+
props.setProperty("verifyServerCertificate", "false");
91+
break;
92+
case VERIFY:
93+
props.setProperty("useSSL", "true");
94+
props.setProperty("requireSSL", "true");
95+
props.setProperty("verifyServerCertificate", "true");
96+
break;
97+
}
9398

9499
if (t.getFetchRows() == 1) {
95100
logger.info("Fetch size is 1. Fetching rows one by one.");

0 commit comments

Comments
 (0)