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: run:
shell: bash shell: bash
env: env:
LIBRETIME_CONF_FILE: /tmp/libretime-test.conf LIBRETIME_CONFIG_FILEPATH: /tmp/libretime-test.conf
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -222,7 +222,7 @@ jobs:
- name: Setup libretime configuration - name: Setup libretime configuration
run: | run: |
cat <<EOF > $LIBRETIME_CONF_FILE cat <<EOF > $LIBRETIME_CONFIG_FILEPATH
[general] [general]
api_key = test_key api_key = test_key
[database] [database]
@ -231,7 +231,7 @@ jobs:
dbuser = postgres dbuser = postgres
dbpass = libretime dbpass = libretime
EOF EOF
cat $LIBRETIME_CONF_FILE cat $LIBRETIME_CONFIG_FILEPATH
- name: Test - name: Test
run: make test run: make test

View File

@ -4,16 +4,22 @@ import sys
from .utils import get_random_string, read_config_file 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" 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: try:
CONFIG = read_config_file(DEFAULT_CONFIG_PATH) CONFIG = read_config_file(LIBRETIME_CONFIG_FILEPATH)
except IOError as e: 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) print(e, file=sys.stderr)
CONFIG = configparser.ConfigParser() CONFIG = configparser.ConfigParser()
@ -144,7 +150,7 @@ USE_TZ = True
STATIC_URL = "/api/static/" STATIC_URL = "/api/static/"
if not DEBUG: 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" AUTH_USER_MODEL = "libretime_api.User"