import os from pydantic_settings import BaseSettings from typing import List # Docker-first: load secrets from mounted files when env vars are absent _PG_SECRET_FILE = os.getenv("POSTGRES_PASSWORD_FILE", "/run/secrets/postgres-password") if not os.getenv("POSTGRES_PASSWORD"): try: with open(_PG_SECRET_FILE, 'r') as f: os.environ["POSTGRES_PASSWORD"] = f.read().strip() except Exception: # Leave as-is; connection will fail loudly if missing pass class Settings(BaseSettings): """Application configuration""" # Database settings POSTGRES_HOST: str = os.getenv("POSTGRES_HOST", "mvp-platform-vehicles-db") POSTGRES_PORT: int = int(os.getenv("POSTGRES_PORT", "5432")) POSTGRES_USER: str = os.getenv("POSTGRES_USER", "mvp_platform_user") POSTGRES_PASSWORD: str = os.getenv("POSTGRES_PASSWORD", "") POSTGRES_DATABASE: str = os.getenv("POSTGRES_DATABASE", "vehicles") # Redis settings REDIS_HOST: str = os.getenv("REDIS_HOST", "mvp-platform-vehicles-redis") REDIS_PORT: int = int(os.getenv("REDIS_PORT", "6379")) REDIS_DB: int = int(os.getenv("REDIS_DB", "0")) # Database connection pool settings DATABASE_MIN_CONNECTIONS: int = int(os.getenv("DATABASE_MIN_CONNECTIONS", "5")) DATABASE_MAX_CONNECTIONS: int = int(os.getenv("DATABASE_MAX_CONNECTIONS", "20")) # Cache settings CACHE_TTL: int = int(os.getenv("CACHE_TTL", "3600")) # 1 hour default # Security API_KEY: str = os.getenv("API_KEY", "mvp-platform-vehicles-secret-key") # Application settings DEBUG: bool = os.getenv("DEBUG", "false").lower() == "true" CORS_ORIGINS: List[str] = [ "http://localhost:3000", "https://motovaultpro.com", "http://localhost:3001" ] class Config: case_sensitive = True def get_settings() -> Settings: """Get application settings""" return Settings()