From 88f0673470a3abf8ea9445a27e719e1aa360235d Mon Sep 17 00:00:00 2001 From: Philipp Horstenkamp Date: Sat, 21 Oct 2023 17:57:56 +0200 Subject: [PATCH] Slimmed down the env vars access and added logging in case the password protection was disabled. (#252) Slimmed down the env vars access and added logging in case the password protection was disabled. --- src/aki_prj23_transparenzregister/ui/protection.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/aki_prj23_transparenzregister/ui/protection.py b/src/aki_prj23_transparenzregister/ui/protection.py index 5bd4509..62ab004 100644 --- a/src/aki_prj23_transparenzregister/ui/protection.py +++ b/src/aki_prj23_transparenzregister/ui/protection.py @@ -12,8 +12,13 @@ def add_auth(app: Dash) -> None: Args: app: The app a basic auth should be added to. """ - if os.getenv("PYTHON_DASH_LOGIN_USERNAME") and os.getenv("PYTHON_DASH_LOGIN_PW"): - login = os.getenv("PYTHON_DASH_LOGIN_USERNAME") - pw = os.getenv("PYTHON_DASH_LOGIN_PW") + if (login := os.getenv("PYTHON_DASH_LOGIN_USERNAME", None)) and ( + pw := os.getenv("PYTHON_DASH_LOGIN_PW", None) + ): logger.info("Staring app in password protected mode!") dash_auth.BasicAuth(app, {login: pw}) + return + logger.info("The password protection is not or only partially configured!") + logger.debug( + "The enviromental variables PYTHON_DASH_LOGIN_USERNAME and PYTHON_DASH_LOGIN_PW should be used to activate this feature." + )