diff --git a/fence/config.py b/fence/config.py index 1c7ff15b9..0010800a0 100644 --- a/fence/config.py +++ b/fence/config.py @@ -49,16 +49,14 @@ 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 - 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" - ) + # Read in all environment variables starting with FENCE_ + for env_var, env_val in os.environ.items(): + if env_var.startswith("FENCE_"): + config_key = env_var[6:] # remove "FENCE_" prefix + self[config_key] = env_val + logger.info( + f"Found environment variable '{env_var}': overriding '{config_key}' 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"])