8000 Enable reading SSL parameters from configuration file (#552) · uwydoc/PyMySQL@557d0d9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 557d0d9

Browse files
JAORMXmethane
authored andcommitted
Enable reading SSL parameters from configuration file (PyMySQL#552)
This enables the reading of some basic SSL parameters from the configuration file. It gives precedence to the ssl parameters provided by the class parameter (the ssl dict).
1 parent 3ccaeda commit 557d0d9

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

pymysql/connections.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -604,14 +604,6 @@ def __init__(self, host=None, user=None, password="",
604604
if self._local_infile:
605605
client_flag |= CLIENT.LOCAL_FILES
606606

607-
self.ssl = False
608-
if ssl:
609-
if not SSL_ENABLED:
610-
raise NotImplementedError("ssl module not found")
611-
self.ssl = True
612-
client_flag |= CLIENT.SSL
613-
self.ctx = self._create_ssl_ctx(ssl)
614-
615607
if read_default_group and not read_default_file:
616608
if sys.platform.startswith("win"):
617609
read_default_file = "c:\\my.ini"
@@ -641,6 +633,21 @@ def _config(key, arg):
641633
port = int(_config("port", port))
642634
bind_address = _config("bind-address", bind_address)
643635
charset = _config("default-character-set", charset)
636+
if not ssl:
637+
ssl = {}
638+
if isinstance(ssl, dict):
639+
for key in ["ca", "capath", "cert", "key", "cipher"]:
640+
value = _config("ssl-" + key, ssl.get(key))
641+
if value:
642+
ssl[key] = value
643+
644+
self.ssl = False
645+
if ssl:
646+
if not SSL_ENABLED:
647+
raise NotImplementedError("ssl module not found")
648+
self.ssl = True
649+
client_flag |= CLIENT.SSL
650+
self.ctx = self._create_ssl_ctx(ssl)
644651

645652
self.host = host or "localhost"
646653
self.port = port or 3306

0 commit comments

Comments
 (0)
0