From 4cebb95a48384c2592745090fd03ef20735ebe4f Mon Sep 17 00:00:00 2001 From: Stefan Hynek <stefan.hynek@uni-goettingen.de> Date: Fri, 5 Nov 2021 09:31:20 +0100 Subject: [PATCH] feat(config): add AppConfig with property "dsn" for sentry initialization --- src/repdav/config.py | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/repdav/config.py b/src/repdav/config.py index dd50e85..8f2e89e 100644 --- a/src/repdav/config.py +++ b/src/repdav/config.py @@ -1,49 +1,61 @@ -import logging import os -from .errors import EnvNotSetError +from .errors import EnvNotSetError -_logger = logging.getLogger(__name__) +# TODO: remove "tg_auth_wsdl", "tg_auth_address", "tg_nav_address" def lookup_env_name(internal_name: str) -> str: mapping = { - "_auth_wsdl" : "tg_auth_wsdl", - "_auth_address" : "tg_auth_address", - "_nav_address" : "tg_nav_address", - "_host" : "tg_host", + "_auth_wsdl": "tg_auth_wsdl", + "_auth_address": "tg_auth_address", + "_dsn": "sentry_dsn", + "_host": "tg_host", + "_nav_address": "tg_nav_address", } return mapping[internal_name] + # TODO check for trailing "/", add if missing! +# TODO check URLs for validity + +class AppConfig: + # TODO: configure the app according to the set environment (i.e. prod or dev) + def __init__(self) -> None: + self._dsn = os.getenv(lookup_env_name("_dsn")) + + @property + def dsn(self) -> str: + return self._dsn + + class TextgridConfig: - def __init__(self): + def __init__(self) -> None: self._auth_wsdl = os.getenv(lookup_env_name("_auth_wsdl")) self._auth_address = os.getenv(lookup_env_name("_auth_address")) - self._nav_address = os.getenv(lookup_env_name("_nav_address")) - self._host = os.getenv(lookup_env_name("_host")) + self._nav_address = os.getenv(lookup_env_name("_nav_address")) + self._host = os.getenv(lookup_env_name("_host")) @property - def auth_wsdl(self): + def auth_wsdl(self) -> str: if self._auth_wsdl: - _logger.debug(self._auth_wsdl) return self._auth_wsdl raise EnvNotSetError(lookup_env_name("_auth_wsdl")) @property - def auth_address(self): + def auth_address(self) -> str: if self._auth_address: return self._auth_address raise EnvNotSetError(lookup_env_name("_auth_address")) @property - def nav_address(self): + def nav_address(self) -> str: if self._nav_address: return self._nav_address raise EnvNotSetError(lookup_env_name("_nav_address")) @property - def host(self): + def host(self) -> str: if self._host: return self._host raise EnvNotSetError(lookup_env_name("_host")) -- GitLab