config.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. # ClickHouse
  11. CLICKHOUSE_HOST: str = "localhost"
  12. CLICKHOUSE_PORT: int = 8123
  13. CLICKHOUSE_USER: str = "default"
  14. CLICKHOUSE_PASSWORD: str = ""
  15. CLICKHOUSE_DATABASE: str = "mybeacon"
  16. # Redis
  17. REDIS_URL: str = "redis://localhost:6379/0"
  18. # Security
  19. SECRET_KEY: str
  20. ENCRYPTION_KEY: str # Fernet key for encrypting WiFi passwords
  21. ACCESS_TOKEN_EXPIRE_MINUTES: int = 15
  22. REFRESH_TOKEN_EXPIRE_DAYS: int = 30
  23. ALGORITHM: str = "HS256"
  24. # CORS
  25. CORS_ORIGINS: str = "http://localhost:5173"
  26. # File Storage
  27. UPLOAD_DIR: str = "/var/lib/mybeacon/uploads"
  28. # Email
  29. SMTP_HOST: str = "localhost"
  30. SMTP_PORT: int = 587
  31. SMTP_USER: str = ""
  32. SMTP_PASSWORD: str = ""
  33. SMTP_FROM: str = "noreply@mybeacon.com"
  34. # Application
  35. DEBUG: bool = False
  36. LOG_LEVEL: str = "INFO"
  37. API_V1_PREFIX: str = "/api/v1"
  38. PROJECT_NAME: str = "MyBeacon API"
  39. model_config = SettingsConfigDict(
  40. env_file=".env",
  41. env_file_encoding="utf-8",
  42. case_sensitive=False
  43. )
  44. @property
  45. def cors_origins_list(self) -> list[str]:
  46. """Parse CORS_ORIGINS string into list."""
  47. return [origin.strip() for origin in self.CORS_ORIGINS.split(",")]
  48. # Global settings instance
  49. settings = Settings()