From ad7686e8a799f820918b9804528233bb5d322f74 Mon Sep 17 00:00:00 2001 From: jo Date: Sat, 15 Jan 2022 18:13:29 +0100 Subject: [PATCH] feat(api): update env var settings loading BREAKING CHANGE: environment variables names changed 'LIBRETIME_CONF_DIR' was removed 'LIBRETIME_CONF_FILE' was renamed to 'LIBRETIME_CONFIG_FILEPATH' --- .github/workflows/test.yml | 6 +++--- api/libretime_api/settings.py | 20 +++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 452e396d2..8707b725f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -208,7 +208,7 @@ jobs: run: shell: bash env: - LIBRETIME_CONF_FILE: /tmp/libretime-test.conf + LIBRETIME_CONFIG_FILEPATH: /tmp/libretime-test.conf steps: - uses: actions/checkout@v2 @@ -222,7 +222,7 @@ jobs: - name: Setup libretime configuration run: | - cat < $LIBRETIME_CONF_FILE + cat < $LIBRETIME_CONFIG_FILEPATH [general] api_key = test_key [database] @@ -231,7 +231,7 @@ jobs: dbuser = postgres dbpass = libretime EOF - cat $LIBRETIME_CONF_FILE + cat $LIBRETIME_CONFIG_FILEPATH - name: Test run: make test diff --git a/api/libretime_api/settings.py b/api/libretime_api/settings.py index 7bd62ce1f..354eee43b 100644 --- a/api/libretime_api/settings.py +++ b/api/libretime_api/settings.py @@ -4,16 +4,22 @@ import sys from .utils import get_random_string, read_config_file -LIBRETIME_CONF_DIR = os.getenv("LIBRETIME_CONF_DIR", "/etc/airtime") -DEFAULT_CONFIG_PATH = os.getenv( - "LIBRETIME_CONF_FILE", os.path.join(LIBRETIME_CONF_DIR, "airtime.conf") -) API_VERSION = "2.0.0" +LIBRETIME_LOG_FILEPATH = os.getenv("LIBRETIME_LOG_FILEPATH") +LIBRETIME_CONFIG_FILEPATH = os.getenv( + "LIBRETIME_CONFIG_FILEPATH", + "/etc/airtime/airtime.conf", +) +LIBRETIME_STATIC_ROOT = os.getenv( + "LIBRETIME_STATIC_ROOT", + "/usr/share/airtime/api", +) + try: - CONFIG = read_config_file(DEFAULT_CONFIG_PATH) + CONFIG = read_config_file(LIBRETIME_CONFIG_FILEPATH) except IOError as e: - print(f"Unable to read config file {DEFAULT_CONFIG_PATH}", file=sys.stderr) + print(f"Unable to read config file {LIBRETIME_CONFIG_FILEPATH}", file=sys.stderr) print(e, file=sys.stderr) CONFIG = configparser.ConfigParser() @@ -144,7 +150,7 @@ USE_TZ = True STATIC_URL = "/api/static/" if not DEBUG: - STATIC_ROOT = os.getenv("LIBRETIME_STATIC_ROOT", "/usr/share/airtime/api") + STATIC_ROOT = LIBRETIME_STATIC_ROOT AUTH_USER_MODEL = "libretime_api.User"