diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2023-09-08 14:50:00 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2023-09-08 15:02:26 -0400 |
commit | 3cfb6481353c5016f903b168413fe2a1776c74a4 (patch) | |
tree | f1108e8598d35c964608459b0e602cb937628065 | |
parent | a31a92ff18a0df3b776a2a96d54a87bed65a23de (diff) | |
download | peebz-3cfb6481353c5016f903b168413fe2a1776c74a4.tar.gz |
Allow passing DBURL and BZAPIKEY via env vars
This lets us manage most of the configuration via a git repository, but
source sensitive secrets from an externally managed file.
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r-- | peebz/__init__.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/peebz/__init__.py b/peebz/__init__.py index 2574d44..294fa27 100644 --- a/peebz/__init__.py +++ b/peebz/__init__.py @@ -8,6 +8,7 @@ import logging import base64 import b4 import sys +import os import uuid import datetime import gzip @@ -104,7 +105,10 @@ def bz_rest(path: str, payload: Dict = None, params: Dict = None, method: str = url = '{BZURL}/{path}'.format(BZURL=config['bugzilla'].get('resturl').rstrip('/'), path=path) logger.debug('Querying url=%s', url) myparams = dict() if params is None else dict(params) - myparams['api_key'] = config['bugzilla'].get('apikey', '') + apikey = config['bugzilla'].get('apikey') + if not apikey: + apikey = os.getenv('BZAPIKEY', '') + myparams['api_key'] = apikey ses = get_requests_session() if method == 'GET': res = ses.get(url, params=myparams) @@ -968,7 +972,10 @@ def db_get_sa() -> Tuple[sa.engine.Engine, sa.engine.Connection]: try: dburl = config['db']['dburl'] except KeyError: - raise LookupError('CRITICAL: main.dburl not set in config file') + # we may pass it via env, which lets us better manage secrets + dburl = os.getenv('DBURL') + if not dburl: + raise LookupError('CRITICAL: main.dburl not set in config file') db_pool_recycle = int(config['db'].get('dbpoolrecycle', '300')) SAENGINE = sa.create_engine(dburl, pool_recycle=db_pool_recycle) |