From a73273c32a1c968db21a0c53b6023f8934a6de1f Mon Sep 17 00:00:00 2001 From: Jawad Qureshi Date: Tue, 8 Nov 2022 10:25:58 -0600 Subject: [PATCH 1/2] feat(dbenvvar): db connection info from env --- .secrets.baseline | 4 ++-- fence/config-default.yaml | 1 + fence/config.py | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index 7974f4d3f..9dd85ba20 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -155,7 +155,7 @@ "filename": "fence/config-default.yaml", "hashed_secret": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3", "is_verified": false, - "line_number": 31 + "line_number": 32 } ], "fence/local_settings.example.py": [ @@ -334,5 +334,5 @@ } ] }, - "generated_at": "2022-08-12T15:25:33Z" + "generated_at": "2022-11-08T16:17:42Z" } diff --git a/fence/config-default.yaml b/fence/config-default.yaml index 6776d4455..3375eeeef 100755 --- a/fence/config-default.yaml +++ b/fence/config-default.yaml @@ -28,6 +28,7 @@ BASE_URL: 'http://localhost/user' # postgres db to connect to # connection url format: # postgresql://[user[:password]@][netloc][:port][/dbname] +# can also be set via env var DB DB: 'postgresql://test:test@localhost:5432/fence' # A URL-safe base64-encoded 32-byte key for encrypting keys in db diff --git a/fence/config.py b/fence/config.py index 32eed9575..57943d3fe 100644 --- a/fence/config.py +++ b/fence/config.py @@ -49,6 +49,9 @@ def post_process(self): for default in defaults: self.force_default_if_none(default, default_cfg=default_config) + # allow setting DB connection string via env var + self["DB"] = os.environ.get("DB", self["DB"]) + if "ROOT_URL" not in self._configs and "BASE_URL" in self._configs: url = urllib.parse.urlparse(self._configs["BASE_URL"]) self._configs["ROOT_URL"] = "{}://{}".format(url.scheme, url.netloc) From 230e11b8a747ed47b37033677dca4ac2a5f6b5aa Mon Sep 17 00:00:00 2001 From: Pauline Ribeyre <4224001+paulineribeyre@users.noreply.github.com> Date: Tue, 6 Dec 2022 11:17:46 -0600 Subject: [PATCH 2/2] add info log --- fence/config.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fence/config.py b/fence/config.py index 57943d3fe..ca149991d 100644 --- a/fence/config.py +++ b/fence/config.py @@ -50,7 +50,11 @@ def post_process(self): self.force_default_if_none(default, default_cfg=default_config) # allow setting DB connection string via env var - self["DB"] = os.environ.get("DB", self["DB"]) + if os.environ.get("DB"): + logger.info("Found environment variable 'DB': overriding 'DB' field from config file") + self["DB"] = os.environ["DB"] + else: + logger.info("Environment variable 'DB' empty or not set: using 'DB' field from config file") if "ROOT_URL" not in self._configs and "BASE_URL" in self._configs: url = urllib.parse.urlparse(self._configs["BASE_URL"])