fix(config): return None if env var is empty or non-existent #315

Merged
luketainton merged 4 commits from 278-bug-handle-empty-or-undefined-environment-variables-for-approved-usersroomsdomains into main 2024-11-21 23:26:07 +01:00
Showing only changes of commit f279ecba4a - Show all commits

View File

@ -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()