From c38c7c89ecc2918c54e4cdf9905b7c6d131d5991 Mon Sep 17 00:00:00 2001 From: devthejo Date: Thu, 21 Mar 2024 22:50:18 +0100 Subject: [PATCH] fix: sslrequire --- packages/api/egapro/db.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/api/egapro/db.py b/packages/api/egapro/db.py index 18be0eedd..1c9b43f68 100644 --- a/packages/api/egapro/db.py +++ b/packages/api/egapro/db.py @@ -1,5 +1,6 @@ from typing import KeysView, Literal, Union import uuid +import ssl from datetime import datetime import asyncpg @@ -673,6 +674,12 @@ async def set_type_codecs(conn): async def init(): try: + if config.DBSSL == "require": + sslctx = ssl.create_default_context(ssl.Purpose.SERVER_AUTH) + sslctx.check_hostname = False + sslctx.verify_mode = ssl.CERT_NONE + else: + sslctx = config.DBSSL table.pool = await asyncpg.create_pool( database=config.DBNAME, host=config.DBHOST, @@ -682,7 +689,7 @@ async def init(): min_size=config.DBMINSIZE, max_size=config.DBMAXSIZE, init=set_type_codecs, - ssl=config.DBSSL, + ssl=sslctx, ) except (OSError, PostgresError) as err: raise RuntimeError(f"CRITICAL Cannot connect to DB: {err}")