fix(config): return None if env var is empty or non-existent #315
@ -69,23 +69,32 @@ class Config:
|
|||||||
return os.environ["N8N_WEBHOOK_URL"]
|
return os.environ["N8N_WEBHOOK_URL"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def approved_users(self) -> list:
|
def approved_users(self) -> list | None:
|
||||||
"""Returns a list of approved users."""
|
"""Returns a list of approved users."""
|
||||||
emails: list[str] = os.environ.get("APPROVED_USERS", "").split(",")
|
_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] = [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
|
return emails
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def approved_rooms(self) -> list:
|
def approved_rooms(self) -> list | None:
|
||||||
"""Returns a list of approved rooms."""
|
"""Returns a list of approved rooms."""
|
||||||
rooms: list[str] = os.environ.get("APPROVED_ROOMS", "").split(",")
|
_rooms: list[str] = os.environ.get("APPROVED_ROOMS", "").split(",")
|
||||||
return [i.strip() for i in rooms]
|
rooms: list[str] = [i.strip() for i in _rooms if i]
|
||||||
|
if not rooms:
|
||||||
|
return None
|
||||||
|
return rooms
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def approved_domains(self) -> list:
|
def approved_domains(self) -> list | None:
|
||||||
"""Returns a list of approved domains."""
|
"""Returns a list of approved domains."""
|
||||||
domains: list[str] = os.environ.get("APPROVED_DOMAINS", "").split(",")
|
_domains: list[str] = os.environ.get("APPROVED_DOMAINS", "").split(",")
|
||||||
return [i.strip() for i in domains]
|
domains: list[str] = [i.strip() for i in _domains if i]
|
||||||
|
if not domains:
|
||||||
|
return None
|
||||||
|
return domains
|
||||||
|
|
||||||
|
|
||||||
config: Config = Config()
|
config: Config = Config()
|
||||||
|
Loading…
Reference in New Issue
Block a user