|
58 | 58 | from mycli.clitoolbar import create_toolbar_tokens_func |
59 | 59 | from mycli.compat import WIN |
60 | 60 | from mycli.completion_refresher import CompletionRefresher |
61 | | -from mycli.config import get_mylogin_cnf_path, open_mylogin_cnf, read_config_files, str_to_bool, strip_matching_quotes, write_default_config |
| 61 | +from mycli.config import ( |
| 62 | + get_mylogin_cnf_path, |
| 63 | + open_mylogin_cnf, |
| 64 | + read_config_files, |
| 65 | + str_to_bool, |
| 66 | + str_to_on_off, |
| 67 | + strip_matching_quotes, |
| 68 | + write_default_config, |
| 69 | +) |
62 | 70 | from mycli.constants import ISSUES_URL |
63 | 71 | from mycli.key_bindings import mycli_bindings |
64 | 72 | from mycli.lexer import MyCliLexer |
@@ -226,7 +234,9 @@ def __init__( |
226 | 234 |
|
227 | 235 | # set ssl_mode if a valid option is provided in a config file, otherwise None |
228 | 236 | ssl_mode = c["main"].get("ssl_mode", None) or c["connection"].get("default_ssl_mode", None) |
229 | | - if ssl_mode not in ("auto", "on", "off", None): |
| 237 | + if ssl_mode is None: |
| 238 | + self.ssl_mode = ssl_mode |
| 239 | + elif ssl_mode.lower() not in ("auto", "on", "off", "1", "0", "true", "false"): |
230 | 240 | self.echo(f"Invalid config option provided for ssl_mode ({ssl_mode}); ignoring.", err=True, fg="red") |
231 | 241 | self.ssl_mode = None |
232 | 242 | else: |
@@ -1720,7 +1730,7 @@ def get_last_query(self) -> str | None: |
1720 | 1730 | "--ssl-mode", |
1721 | 1731 | "ssl_mode", |
1722 | 1732 | help="Set desired SSL behavior. auto=preferred if TCP/IP, on=required, off=off.", |
1723 | | - type=click.Choice(["auto", "on", "off"]), |
| 1733 | + type=str, |
1724 | 1734 | ) |
1725 | 1735 | @click.option("--ssl/--no-ssl", "ssl_enable", default=None, help="Enable SSL for connection (automatically enabled with other flags).") |
1726 | 1736 | @click.option("--ssl-ca", help="CA file in PEM format.", type=click.Path(exists=True)) |
@@ -2080,6 +2090,14 @@ def get_password_from_file(password_file: str | None) -> str | None: |
2080 | 2090 |
|
2081 | 2091 | keepalive_ticks = keepalive_ticks if keepalive_ticks is not None else mycli.default_keepalive_ticks |
2082 | 2092 | ssl_mode = ssl_mode or mycli.ssl_mode # cli option or config option |
| 2093 | + if ssl_mode: |
| 2094 | + ssl_mode = ssl_mode.lower() |
| 2095 | + if ssl_mode and ssl_mode != 'auto': |
| 2096 | + try: |
| 2097 | + ssl_mode = str_to_on_off(ssl_mode) |
| 2098 | + except ValueError: |
| 2099 | + click.secho('Unknown value for ssl_mode', err=True, fg='red') |
| 2100 | + sys.exit(1) |
2083 | 2101 |
|
2084 | 2102 | # if there is a mismatch between the ssl_mode value and other sources of ssl config, show a warning |
2085 | 2103 | # specifically using "is False" to not pickup the case where ssl_enable is None (not set by the user) |
|
0 commit comments