Skip to content

Commit

Permalink
fix: sslrequire
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Mar 21, 2024
1 parent 57481df commit c38c7c8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/api/egapro/db.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import KeysView, Literal, Union
import uuid
import ssl
from datetime import datetime

import asyncpg
Expand Down Expand Up @@ -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,
Expand All @@ -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}")
Expand Down

0 comments on commit c38c7c8

Please sign in to comment.