From 5f5e33daaf909a5dbc5b0a1730c7510f19576548 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 9 Dec 2024 10:40:42 -0600 Subject: Parse for SSL_MODE option values from a list of acceptable values. --- gn_libs/mysqldb.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gn_libs') diff --git a/gn_libs/mysqldb.py b/gn_libs/mysqldb.py index d620b11..4997ac7 100644 --- a/gn_libs/mysqldb.py +++ b/gn_libs/mysqldb.py @@ -29,6 +29,15 @@ def __non_negative_int__(val: str) -> int: _val = int(val) assert (val >= 0), f"Expected a non-negative value. Got {_val}" return _val + + +def __parse_ssl_mode_options__(val: str) -> str: + mode_opts = ( + "DISABLED", "PREFERRED", "REQUIRED", "VERIFY_CA", "VERIFY_IDENTITY") + _val = val.strip().upper() + if(_val not in mode_opts): + raise InvalidOptionValue(f"Invalid ssl_mode option: {_val}") + return _val def __parse_db_opts__(opts: str) -> dict: """Parse database options into their appropriate values. @@ -48,6 +57,7 @@ def __parse_db_opts__(opts: str) -> dict: "client_flag": int, # "ssl": __parse_ssl_options__, "multi_statements": __parse_boolean__, + "ssl_mode": __parse_ssl_mode_options__, "local_infile": __parse_boolean__, "autocommit": __parse_boolean__, "binary_prefix": __parse_boolean__ -- cgit v1.2.3