From 7f626c89e55c777e3c2cb77999af5927eab94552 Mon Sep 17 00:00:00 2001 From: Frugan Date: Tue, 4 Jun 2024 20:48:13 +0200 Subject: [PATCH] :construction_worker: add --mysql-ssl-{cert,key,ca} options --- README.md | 3 +++ docs/README.rst | 5 ++++- src/mysql_to_sqlite3/cli.py | 9 +++++++++ src/mysql_to_sqlite3/transporter.py | 9 +++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b6feb95..7ebcb6a 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,9 @@ Options: --mysql-charset TEXT MySQL database and table character set [default: utf8mb4] --mysql-collation TEXT MySQL database and table collation + --mysql-ssl-cert PATH Path to SSL certificate file. + --mysql-ssl-key PATH Path to SSL key file. + --mysql-ssl-ca PATH Path to SSL CA certificate file. -S, --skip-ssl Disable MySQL connection encryption. -c, --chunk INTEGER Chunk reading/writing SQL records -l, --log-file PATH Log file diff --git a/docs/README.rst b/docs/README.rst index 3eb421e..907644f 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -45,7 +45,10 @@ Connection Options - ``-h, --mysql-host TEXT``: MySQL host. Defaults to localhost. - ``-P, --mysql-port INTEGER``: MySQL port. Defaults to 3306. - ``--mysql-charset TEXT``: MySQL database and table character set. The default is utf8mb4. -- ``--mysql-collation TEXT``: MySQL database and table collation +- ``--mysql-collation TEXT``: MySQL database and table collation. +- ``--mysql-ssl-cert PATH``: Path to SSL certificate file. +- ``--mysql-ssl-key PATH``: Path to SSL key file. +- ``--mysql-ssl-ca PATH``: Path to SSL CA certificate file. - ``-S, --skip-ssl``: Disable MySQL connection encryption. Other Options diff --git a/src/mysql_to_sqlite3/cli.py b/src/mysql_to_sqlite3/cli.py index cd9bc26..31f81a1 100644 --- a/src/mysql_to_sqlite3/cli.py +++ b/src/mysql_to_sqlite3/cli.py @@ -126,6 +126,9 @@ default=None, help="MySQL database and table collation", ) +@click.option("--mysql-ssl-cert", type=click.Path(), help="Path to SSL certificate file.") +@click.option("--mysql-ssl-key", type=click.Path(), help="Path to SSL key file.") +@click.option("--mysql-ssl-ca", type=click.Path(), help="Path to SSL CA certificate file.") @click.option("-S", "--skip-ssl", is_flag=True, help="Disable MySQL connection encryption.") @click.option( "-c", @@ -171,6 +174,9 @@ def cli( mysql_port: int, mysql_charset: str, mysql_collation: str, + mysql_ssl_cert: t.Optional[str], + mysql_ssl_key: t.Optional[str], + mysql_ssl_ca: t.Optional[str], skip_ssl: bool, chunk: int, log_file: t.Union[str, "os.PathLike[t.Any]"], @@ -219,6 +225,9 @@ def cli( mysql_port=mysql_port, mysql_charset=mysql_charset, mysql_collation=mysql_collation, + mysql_ssl_cert=mysql_ssl_cert, + mysql_ssl_key=mysql_ssl_key, + mysql_ssl_ca=mysql_ssl_ca, mysql_ssl_disabled=skip_ssl, chunk=chunk, json_as_text=json_as_text, diff --git a/src/mysql_to_sqlite3/transporter.py b/src/mysql_to_sqlite3/transporter.py index c6151de..84294bd 100644 --- a/src/mysql_to_sqlite3/transporter.py +++ b/src/mysql_to_sqlite3/transporter.py @@ -100,6 +100,12 @@ def __init__(self, **kwargs: tx.Unpack[MySQLtoSQLiteParams]) -> None: if self._without_tables and self._without_data: raise ValueError("Unable to continue without transferring data or creating tables!") + self._mysql_ssl_ca = kwargs.get("mysql_ssl_ca") or None + + self._mysql_ssl_cert = kwargs.get("mysql_ssl_cert") or None + + self._mysql_ssl_key = kwargs.get("mysql_ssl_key") or None + self._mysql_ssl_disabled = bool(kwargs.get("mysql_ssl_disabled", False)) self._current_chunk_number = 0 @@ -135,6 +141,9 @@ def __init__(self, **kwargs: tx.Unpack[MySQLtoSQLiteParams]) -> None: password=self._mysql_password, host=self._mysql_host, port=self._mysql_port, + ssl_ca=self._mysql_ssl_ca, + ssl_cert=self._mysql_ssl_cert, + ssl_key=self._mysql_ssl_key, ssl_disabled=self._mysql_ssl_disabled, charset=self._mysql_charset, collation=self._mysql_collation,