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.
This commit is contained in:
Philipp Horstenkamp 2023-10-21 17:57:56 +02:00 committed by GitHub
parent 55ebb4c17d
commit 88f0673470
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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