Skip to content

Commit

Permalink
Allow to use external configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Nov 12, 2024
1 parent 3447948 commit 5257f65
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions src/lvmapi/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
9 changes: 8 additions & 1 deletion src/lvmapi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 5257f65

Please sign in to comment.