Skip to content

Commit bc856f9

Browse files
committed
prioritize passed SSLContext
1 parent 457e26f commit bc856f9

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

asyncpg/connect_utils.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -452,27 +452,28 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
452452
ssl.verify_mode = ssl_module.CERT_REQUIRED
453453
if sslmode <= SSLMode.require:
454454
ssl.verify_mode = ssl_module.CERT_NONE
455+
456+
if sslcert is None:
457+
sslcert = os.getenv('PGSSLCERT')
458+
459+
if sslkey is None:
460+
sslkey = os.getenv('PGSSLKEY')
461+
462+
if sslrootcert is None:
463+
sslrootcert = os.getenv('PGSSLROOTCERT')
464+
465+
if sslcert:
466+
ssl.load_cert_chain(sslcert, keyfile=sslkey)
467+
468+
if sslrootcert:
469+
ssl.load_verify_locations(cafile=sslrootcert)
470+
455471
elif ssl is True:
456472
ssl = ssl_module.create_default_context()
457473
sslmode = SSLMode.verify_full
458474
else:
459475
sslmode = SSLMode.disable
460476

461-
if sslcert is None:
462-
sslcert = os.getenv('PGSSLCERT')
463-
464-
if sslkey is None:
465-
sslkey = os.getenv('PGSSLKEY')
466-
467-
if sslrootcert is None:
468-
sslrootcert = os.getenv('PGSSLROOTCERT')
469-
470-
if isinstance(ssl, ssl_module.SSLContext):
471-
if sslcert:
472-
ssl.load_cert_chain(sslcert, keyfile=sslkey)
473-
if sslrootcert:
474-
ssl.load_verify_locations(cafile=sslrootcert)
475-
476477
if server_settings is not None and (
477478
not isinstance(server_settings, dict) or
478479
not all(isinstance(k, str) for k in server_settings) or

0 commit comments

Comments
 (0)