40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from functools import lru_cache
|
|
from os import getenv
|
|
from pathlib import Path
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
|
load_dotenv(PROJECT_ROOT / ".env")
|
|
|
|
|
|
def _env_bool(name: str, default: bool) -> bool:
|
|
value = getenv(name)
|
|
if value is None:
|
|
return default
|
|
return value.strip().lower() in {"1", "true", "yes", "on"}
|
|
|
|
|
|
class Settings:
|
|
def __init__(self) -> None:
|
|
self.session_secret_key = getenv(
|
|
"SESSION_SECRET_KEY", "change-me-in-production"
|
|
)
|
|
self.azure_tenant_id = getenv("AZURE_TENANT_ID")
|
|
self.azure_client_id = getenv("AZURE_CLIENT_ID")
|
|
self.azure_client_secret = getenv("AZURE_CLIENT_SECRET")
|
|
self.azure_oauth_verify_ssl = _env_bool("AZURE_OAUTH_VERIFY_SSL", True)
|
|
self.azure_oauth_ca_bundle = getenv("AZURE_OAUTH_CA_BUNDLE")
|
|
|
|
@property
|
|
def azure_configured(self) -> bool:
|
|
return bool(
|
|
self.azure_tenant_id and self.azure_client_id and self.azure_client_secret
|
|
)
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
return Settings()
|