Skip to content

Commit

Permalink
Enable reading SSL parameters from configuration file (#552)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
JAORMX authored and methane committed Feb 28, 2017
1 parent 3ccaeda commit 557d0d9
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions pymysql/connections.py
Expand Up @@ -604,14 +604,6 @@ def __init__(self, host=None, user=None, password="",
if self._local_infile:
client_flag |= CLIENT.LOCAL_FILES

self.ssl = False
if ssl:
if not SSL_ENABLED:
raise NotImplementedError("ssl module not found")
self.ssl = True
client_flag |= CLIENT.SSL
self.ctx = self._create_ssl_ctx(ssl)

if read_default_group and not read_default_file:
if sys.platform.startswith("win"):
read_default_file = "c:\\my.ini"
Expand Down Expand Up @@ -641,6 +633,21 @@ def _config(key, arg):
port = int(_config("port", port))
bind_address = _config("bind-address", bind_address)
charset = _config("default-character-set", charset)
if not ssl:
ssl = {}
if isinstance(ssl, dict):
for key in ["ca", "capath", "cert", "key", "cipher"]:
value = _config("ssl-" + key, ssl.get(key))
if value:
ssl[key] = value

self.ssl = False
if ssl:
if not SSL_ENABLED:
raise NotImplementedError("ssl module not found")
self.ssl = True
client_flag |= CLIENT.SSL
self.ctx = self._create_ssl_ctx(ssl)

self.host = host or "localhost"
self.port = port or 3306
Expand Down

0 comments on commit 557d0d9

Please sign in to comment.