|
56 | 56 | from mycli.clitoolbar import create_toolbar_tokens_func |
57 | 57 | from mycli.compat import WIN |
58 | 58 | from mycli.completion_refresher import CompletionRefresher |
59 | | -from mycli.config import get_mylogin_cnf_path, open_mylogin_cnf, read_config_files, str_to_bool, strip_matching_quotes, write_default_config |
| 59 | +from mycli.config import ( |
| 60 | + get_mylogin_cnf_path, |
| 61 | + open_mylogin_cnf, |
| 62 | + read_config_files, |
| 63 | + str_to_bool, |
| 64 | + str_to_on_off, |
| 65 | + strip_matching_quotes, |
| 66 | + write_default_config, |
| 67 | +) |
60 | 68 | from mycli.key_bindings import mycli_bindings |
61 | 69 | from mycli.lexer import MyCliLexer |
62 | 70 | from mycli.packages import special |
@@ -220,7 +228,9 @@ def __init__( |
220 | 228 |
|
221 | 229 | # set ssl_mode if a valid option is provided in a config file, otherwise None |
222 | 230 | ssl_mode = c["main"].get("ssl_mode", None) or c["connection"].get("default_ssl_mode", None) |
223 | | - if ssl_mode not in ("auto", "on", "off", None): |
| 231 | + if ssl_mode is None: |
| 232 | + pass |
| 233 | + elif ssl_mode.lower() not in ("auto", "on", "off", "1", "0", "true", "false"): |
224 | 234 | self.echo(f"Invalid config option provided for ssl_mode ({ssl_mode}); ignoring.", err=True, fg="red") |
225 | 235 | self.ssl_mode = None |
226 | 236 | else: |
@@ -1659,7 +1669,7 @@ def get_last_query(self) -> str | None: |
1659 | 1669 | "--ssl-mode", |
1660 | 1670 | "ssl_mode", |
1661 | 1671 | help="Set desired SSL behavior. auto=preferred, on=required, off=off.", |
1662 | | - type=click.Choice(["auto", "on", "off"]), |
| 1672 | + type=str, |
1663 | 1673 | ) |
1664 | 1674 | @click.option("--ssl/--no-ssl", "ssl_enable", default=None, help="Enable SSL for connection (automatically enabled with other flags).") |
1665 | 1675 | @click.option("--ssl-ca", help="CA file in PEM format.", type=click.Path(exists=True)) |
@@ -1995,6 +2005,14 @@ def get_password_from_file(password_file: str | None) -> str | None: |
1995 | 2005 | ssl_enable = True |
1996 | 2006 |
|
1997 | 2007 | ssl_mode = ssl_mode or mycli.ssl_mode # cli option or config option |
| 2008 | + if ssl_mode: |
| 2009 | + ssl_mode = ssl_mode.lower() |
| 2010 | + if ssl_mode and ssl_mode != 'auto': |
| 2011 | + try: |
| 2012 | + ssl_mode = str_to_on_off(ssl_mode) |
| 2013 | + except ValueError: |
| 2014 | + click.secho('Unknown value for ssl_mode', err=True, fg='red') |
| 2015 | + sys.exit(1) |
1998 | 2016 |
|
1999 | 2017 | # if there is a mismatch between the ssl_mode value and other sources of ssl config, show a warning |
2000 | 2018 | # specifically using "is False" to not pickup the case where ssl_enable is None (not set by the user) |
|
0 commit comments