import os from urllib.parse import quote_plus as url_encode from functools import lru_cache from pydantic import BaseSettings, PostgresDsn class Settings(BaseSettings): """Contains application-specific configuration values. Reads the values from environment variables and falls back to default values if the corresponding environment variable is unset. """ app_name: str = os.getenv("APP_NAME", "MEDWingS") admin_email: str = os.getenv("ADMIN_EMAIL", "admin@example.com") debug_mode: bool = False if os.getenv("DEBUG_MODE", "false").lower() == "true": debug_mode = True _pg_hostname = os.getenv("POSTGRES_HOST", "db") _pg_port = os.getenv("POSTGRES_PORT", "5432") _pg_dbname = os.getenv("POSTGRES_DB", "medwings") _pg_user = url_encode(os.getenv("POSTGRES_USER", "medwings")) _pg_password = url_encode(os.getenv("POSTGRES_PASSWORD", "medwings")) pg_dsn: PostgresDsn = f"postgresql://{_pg_user}:{_pg_password}@{_pg_hostname}:{_pg_port}/{_pg_dbname}" @lru_cache def get_settings() -> Settings: """Creates the settings once and returns a cached version on subsequent requests.""" return Settings()