From b1a088da367cd8738249f9f5c502b67e6d2a6c05 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Wed, 12 Aug 2020 14:38:31 +0200 Subject: [PATCH] Prefer environment variables to connect to DB --- bin/configuration.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/configuration.py b/bin/configuration.py index 763faf8..121a1f5 100644 --- a/bin/configuration.py +++ b/bin/configuration.py @@ -17,7 +17,14 @@ def read (file = None): if file is None: file = prefix+"/etc/config.yaml" with open(file, "r") as fd: - return _load(fd) + cfg = _load(fd) + + if "db" in cfg and "connection_string" in cfg["db"] and os.environ.get("PGDATABASE"): + # This should cause the PostgreSQL library to use the environment variables + cfg["db"]["connection_string"] = "" + print("Using environment variables for database connection") + + return cfg def files (globspec = None, include_archived = False): """