Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dbenvvar): db connection info from env #1060

Merged
merged 4 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions fence/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions fence/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ 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")

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)
Expand Down