From f279ecba4aa079abedd45862db4d87345194c91e Mon Sep 17 00:00:00 2001 From: Luke Tainton Date: Thu, 21 Nov 2024 21:36:59 +0000 Subject: [PATCH] fix(config): return None if env var is empty or non-existent --- app/utils/config.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/utils/config.py b/app/utils/config.py index 5cce4b4..84bdfb2 100644 --- a/app/utils/config.py +++ b/app/utils/config.py @@ -69,23 +69,32 @@ class Config: return os.environ["N8N_WEBHOOK_URL"] @property - def approved_users(self) -> list: + def approved_users(self) -> list | None: """Returns a list of approved users.""" - emails: list[str] = os.environ.get("APPROVED_USERS", "").split(",") - emails = [i.strip() for i in emails if validate_email_syntax(i.strip())] + _emails: list[str] = os.environ.get("APPROVED_USERS", "").split(",") + _emails: list[str] = [i.strip() for i in _emails if i] + if not _emails: + return None + emails = [i for i in _emails if validate_email_syntax(i)] return emails @property - def approved_rooms(self) -> list: + def approved_rooms(self) -> list | None: """Returns a list of approved rooms.""" - rooms: list[str] = os.environ.get("APPROVED_ROOMS", "").split(",") - return [i.strip() for i in rooms] + _rooms: list[str] = os.environ.get("APPROVED_ROOMS", "").split(",") + rooms: list[str] = [i.strip() for i in _rooms if i] + if not rooms: + return None + return rooms @property - def approved_domains(self) -> list: + def approved_domains(self) -> list | None: """Returns a list of approved domains.""" - domains: list[str] = os.environ.get("APPROVED_DOMAINS", "").split(",") - return [i.strip() for i in domains] + _domains: list[str] = os.environ.get("APPROVED_DOMAINS", "").split(",") + domains: list[str] = [i.strip() for i in _domains if i] + if not domains: + return None + return domains config: Config = Config()