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'
This commit is contained in:
jo 2022-01-15 18:13:29 +01:00 committed by Kyle Robbertze
parent 19faffea16
commit ad7686e8a7
2 changed files with 16 additions and 10 deletions

View File

@ -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 <<EOF > $LIBRETIME_CONF_FILE
cat <<EOF > $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

View File

@ -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"