Skip to content

Commit 2cde254

Browse files
committed
client cert auth PR review updates
1 parent 2f8c0e7 commit 2cde254

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

aiven_mysql_migrate/migration.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import concurrent
1818
import enum
1919
import logging
20+
import os
2021
import pymysql
2122
import shlex
2223
import signal
@@ -207,6 +208,13 @@ def _check_bin_log_format(self):
207208
if row_format.upper() != "ROW":
208209
raise UnsupportedBinLogFormatException(f"Unsupported binary log format: {row_format}, only ROW is supported")
209210

211+
def _check_ssl_files(self):
212+
if not (config.SOURCE_SSL_CA is None and config.SOURCE_SSL_CERT is None and config.SOURCE_SSL_KEY is None):
213+
if not (os.path.exists(config.SOURCE_SSL_CA) and os.path.exists(config.SOURCE_SSL_CERT) and
214+
os.path.exists(config.SOURCE_SSL_KEY)):
215+
LOGGER.debug("SSL files:[%s],[%s],[%s]", config.SOURCE_SSL_CA, config.SOURCE_SSL_CERT, config.SOURCE_SSL_KEY)
216+
raise WrongMigrationConfigurationException("SSL files error!")
217+
210218
def run_checks(
211219
self,
212220
force_method: Optional[MySQLMigrateMethod] = None,
@@ -229,6 +237,7 @@ def run_checks(
229237
)
230238
migration_method = MySQLMigrateMethod.dump
231239

240+
self._check_ssl_files()
232241
self._check_connections()
233242
self._check_databases_count()
234243
if dbs_max_total_size is not None:

aiven_mysql_migrate/utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def from_uri(
6363
options = parse_qs(res.query)
6464
ssl = not (options and options.get("ssl-mode", ["DISABLE"]) == ["DISABLE"])
6565

66-
LOGGER.debug("from_uri - sslca:[%s], sslcert:[%s], sslkey:[%s]", sslca, sslcert, sslkey)
6766
return MySQLConnectionInfo(
6867
hostname=res.hostname,
6968
port=port,
@@ -78,7 +77,13 @@ def from_uri(
7877

7978
def to_uri(self):
8079
ssl_mode = "DISABLE" if not self.ssl else "REQUIRE"
81-
ssl_auth = urllib.parse.urlencode(f"&ssl-ca={self.sslca}&ssl-cert={self.sslcert}&ssl-key={self.sslkey}") \
80+
81+
ssl_params = {
82+
"ssl-ca": self.sslca,
83+
"ssl-cert": self.sslcert,
84+
"ssl-key": self.sslkey
85+
}
86+
ssl_auth = urllib.parse.urlencode(ssl_params) \
8287
if self.sslca and self.sslcert and self.sslcert else ""
8388
LOGGER.debug("ssl_auth:[%s]]", ssl_auth)
8489
return f"mysql://{self.username}:{self.password}@{self.hostname}:{self.port}/?ssl-mode={ssl_mode}{ssl_auth}"
@@ -107,7 +112,7 @@ def _connect(self):
107112
ssl_key=self.sslkey,
108113
user=self.username,
109114
write_timeout=config.MYSQL_WRITE_TIMEOUT,
110-
)
115+
)
111116

112117
@property
113118
def version(self) -> str:

0 commit comments

Comments
 (0)