From 9df2914b86a1bd4f501562d3e7d92980dfaa1448 Mon Sep 17 00:00:00 2001 From: Dennis Boldt Date: Sun, 2 Jan 2022 18:24:13 +0100 Subject: [PATCH] Allow env-vars starting with OBS_ to configure the portal --- api/obs/api/app.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/api/obs/api/app.py b/api/obs/api/app.py index 5f9e349..678f8fb 100644 --- a/api/obs/api/app.py +++ b/api/obs/api/app.py @@ -24,8 +24,11 @@ from obs.api.db import User, make_session, connect_db log = logging.getLogger(__name__) -app = Sanic("OpenBikeSensor Portal API", log_config={}) -app.update_config("./config.py") +app = Sanic("OpenBikeSensor Portal API", load_env="OBS_", log_config={}) + +if os.path.isfile("./config.py"): + app.update_config("./config.py") + c = app.config api = Blueprint("api", url_prefix="/api") @@ -104,7 +107,11 @@ Session(app, interface=InMemorySessionInterface()) @app.before_server_start async def app_connect_db(app, loop): - app.ctx._db_engine_ctx = connect_db(app.config.POSTGRES_URL, app.config.POSTGRES_POOL_SIZE, app.config.POSTGRES_MAX_OVERFLOW) + app.ctx._db_engine_ctx = connect_db( + app.config.POSTGRES_URL, + app.config.POSTGRES_POOL_SIZE, + app.config.POSTGRES_MAX_OVERFLOW, + ) app.ctx._db_engine = await app.ctx._db_engine_ctx.__aenter__()