diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c20c24..ffd5da8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### ✨ Improved * Switch to using `smtp-02.lco.cl` as mail server. +* Allow to define an external configuration file via the `$LVMAPI_CONFIG_PATH` environment variable. ### 🔧 Fixed diff --git a/src/lvmapi/__init__.py b/src/lvmapi/__init__.py index 5ebda44..909b9e8 100644 --- a/src/lvmapi/__init__.py +++ b/src/lvmapi/__init__.py @@ -1,8 +1,10 @@ # encoding: utf-8 +import os import pathlib -from sdsstools import get_package_version, read_yaml_file +from sdsstools import get_package_version +from sdsstools.configuration import get_config # pip package name @@ -11,5 +13,7 @@ # package name should be pip package name __version__ = get_package_version(path=__file__, package_name=NAME) +internal_config_path = pathlib.Path(__file__).parent / "config.yaml" +config_path = os.getenv("LVMAPI_CONFIG_PATH", None) -config = read_yaml_file(pathlib.Path(__file__).parent / "config.yaml") +config = get_config("lvmapi", config_file=internal_config_path, user_path=config_path) diff --git a/src/lvmapi/app.py b/src/lvmapi/app.py index 6210328..d7bc045 100644 --- a/src/lvmapi/app.py +++ b/src/lvmapi/app.py @@ -8,12 +8,13 @@ from __future__ import annotations +import logging import os import taskiq_fastapi from fastapi import FastAPI, HTTPException, Request -from lvmapi import auth +from lvmapi import auth, config from lvmapi.broker import broker, broker_shutdown, broker_startup from lvmapi.routers import ( actors, @@ -35,6 +36,12 @@ from lvmapi.tools.kubernetes import Kubernetes +logger = logging.getLogger("uvicorn.error") + +if config._CONFIG_FILE is not None: + logger.info(f"Using configuration from {config._CONFIG_FILE}.") + + app = FastAPI(swagger_ui_parameters={"tagsSorter": "alpha"}) app.include_router(auth.router)