config.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """
  2. Application configuration using Pydantic Settings.
  3. Environment variables are loaded from .env file.
  4. """
  5. from pydantic_settings import BaseSettings, SettingsConfigDict
  6. class Settings(BaseSettings):
  7. """Application settings loaded from environment variables."""
  8. # Database
  9. DATABASE_URL: str
  10. # Redis
  11. REDIS_URL: str = "redis://localhost:6379/0"
  12. # Security
  13. SECRET_KEY: str
  14. ENCRYPTION_KEY: str # Fernet key for encrypting WiFi passwords
  15. ACCESS_TOKEN_EXPIRE_MINUTES: int = 15
  16. REFRESH_TOKEN_EXPIRE_DAYS: int = 30
  17. ALGORITHM: str = "HS256"
  18. # CORS
  19. CORS_ORIGINS: str = "http://localhost:5173"
  20. # File Storage
  21. UPLOAD_DIR: str = "/var/lib/mybeacon/uploads"
  22. # Email
  23. SMTP_HOST: str = "localhost"
  24. SMTP_PORT: int = 587
  25. SMTP_USER: str = ""
  26. SMTP_PASSWORD: str = ""
  27. SMTP_FROM: str = "noreply@mybeacon.com"
  28. # Application
  29. DEBUG: bool = False
  30. LOG_LEVEL: str = "INFO"
  31. API_V1_PREFIX: str = "/api/v1"
  32. PROJECT_NAME: str = "MyBeacon API"
  33. model_config = SettingsConfigDict(
  34. env_file=".env",
  35. env_file_encoding="utf-8",
  36. case_sensitive=False
  37. )
  38. @property
  39. def cors_origins_list(self) -> list[str]:
  40. """Parse CORS_ORIGINS string into list."""
  41. return [origin.strip() for origin in self.CORS_ORIGINS.split(",")]
  42. # Global settings instance
  43. settings = Settings()