WS warmup time = 0.3
-# Postgres database configuration; same options as in a connect string
+# Postgres database configuration; same options as in a connect string. Note that because Python's `SSLContext' is used
+# to implement TLS client auth, using `sslkey' to specify a key obtained from an OpenSSL engine may not be supported (a
+# file path is the only option).
[db connect params]
host = example.org
import configparser
import datetime as dt
import logging
+import ssl
from trio import open_memory_channel, open_nursery, open_signal_receiver
ws_silent_limit = dt.timedelta(seconds = main_cfg.getfloat("WS silent limit"))
ws_warmup = dt.timedelta(seconds = main_cfg.getfloat("WS warmup seconds"))
+
db_cfg = parser["db connect params"]
+cert_path = db_cfg.pop("sslcert", None)
+key_path = db_cfg.pop("sslkey", None)
+key_pass = db_cfg.pop("sslpassword", None)
+
getters = {
"port": db_cfg.getint,
}
-db_connect_params = {k: getters.get(k, db_cfg.get)(k) for k in db_cfg}
+db_connect_kwargs = {k: getters.get(k, db_cfg.get)(k) for k in db_cfg}
+
+if cert_path:
+ # patch TLS client cert auth support; asyncpg adds it in a later version
+ db_ssl_ctx = ssl.create_default_context()
+ db_ssl_ctx.load_cert_chain(
+ cert_path,
+ key_path,
+ None if key_pass is None else lambda: key_pass,
+ )
+ db_connect_kwargs["ssl"] = db_ssl_ctx
if read_only and enforcing:
async def main():
async with (
- triopg.connect(**db_connect_params) as db_conn,
+ triopg.connect(**db_connect_kwargs) as db_conn,
open_nursery() as nursery_a,
open_nursery() as nursery_b,
open_nursery() as ws_pool_nursery,