config.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """
  2. app/config.py
  3. ─────────────
  4. Central settings object built from environment variables via pydantic-settings.
  5. All sensitive values must be supplied via the .env file or container env vars —
  6. never hard-coded here.
  7. """
  8. from __future__ import annotations
  9. from typing import Optional
  10. from pydantic_settings import BaseSettings, SettingsConfigDict
  11. class Settings(BaseSettings):
  12. model_config = SettingsConfigDict(
  13. env_file=".env",
  14. env_file_encoding="utf-8",
  15. extra="allow", # allow arbitrary env vars (forwarded to /api/config)
  16. case_sensitive=True,
  17. )
  18. # ── Database ──────────────────────────────────────────────────────────────
  19. DATABASE_URL: str
  20. # ── JWT / Authentication ──────────────────────────────────────────────────
  21. SECRET_KEY: str
  22. ALGORITHM: str = "HS256"
  23. ACCESS_TOKEN_EXPIRE_MINUTES: int = 120
  24. # ── CORS ──────────────────────────────────────────────────────────────────
  25. # Comma-separated list of allowed origins, e.g. "http://localhost:3000,https://pmdi.example.com"
  26. ALLOWED_ORIGINS: str = "http://localhost:3000"
  27. # ── Cron endpoint guard ───────────────────────────────────────────────────
  28. CRON_SECRET_TOKEN: str
  29. # ── Seed admin (first-boot only) ──────────────────────────────────────────
  30. ADMIN_USERNAME: str = "admin"
  31. ADMIN_PASSWORD: str = "changeme"
  32. # ── Mail sender identity ──────────────────────────────────────────────────
  33. MAIL_FROM: str = "noreply@example.com"
  34. MAIL_FROM_NAME: str = "PMDI Invoice System"
  35. # ── Mail Mode A – Authenticated TLS relay ─────────────────────────────────
  36. # All three must be set to activate Mode A.
  37. MAIL_RELAYHOST: Optional[str] = None # "smtp.example.com:587"
  38. MAIL_RELAYHOST_USERNAME: Optional[str] = None
  39. MAIL_RELAYHOST_PASSWORD: Optional[str] = None
  40. # ── Mail Mode B – Simple container/host proxy relay ───────────────────────
  41. # Set to the hostname of the relay container (e.g. "postfix").
  42. MAIL_RELAY_HOST: Optional[str] = None
  43. # Module-level singleton — import this everywhere instead of re-instantiating.
  44. settings = Settings()