# ============================================================================== # Configuración Tipada con Pydantic Settings # Compatible con Windows 10/11, LXC y Docker # ============================================================================== from pathlib import Path from typing import List, Union from pydantic import Field, field_validator from pydantic_settings import BaseSettings, SettingsConfigDict # Directorio raíz del proyecto (OnEverControl) BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent ENV_PATH = BASE_DIR / ".env" class Settings(BaseSettings): model_config = SettingsConfigDict( env_file=str(ENV_PATH) if ENV_PATH.exists() else None, env_file_encoding="utf-8", extra="ignore", ) # Entorno ENVIRONMENT: str = "development" DEBUG: bool = True LOG_LEVEL: str = "INFO" # Servidor SERVER_HOST: str = "0.0.0.0" SERVER_PORT: int = 8000 ALLOWED_ORIGINS: Union[str, List[str]] = [ "http://localhost:5173", "http://127.0.0.1:5173", "http://localhost:8000", "http://127.0.0.1:8000", "https://localhost", "http://localhost", "capacitor://localhost", ] # Base de Datos SQL Server (videoman) DB_SERVER: str = "127.0.0.1" DB_PORT: int = 1433 DB_NAME: str = "videoman" DB_USER: str = "sa" DB_PASSWORD: str = "" DB_CHARSET: str = "CP1252" DB_TIMEOUT: int = 15 # Seguridad JWT SECRET_KEY: str = "dev_secret_key_change_in_production_min_32_chars_1234567890" ACCESS_TOKEN_EXPIRE_MINUTES: int = 43200 # 30 días para puestos de control / tablets persistentes REFRESH_TOKEN_EXPIRE_DAYS: int = 30 # Estación por Defecto DEFAULT_WORKSTATION_NAME: str = "GARITA_PRINCIPAL" @field_validator("ALLOWED_ORIGINS", mode="before") @classmethod def assemble_cors_origins(cls, v: Union[str, List[str]]) -> List[str]: if isinstance(v, str) and not v.startswith("["): return [i.strip() for i in v.split(",") if i.strip()] elif isinstance(v, list): return v return ["*"] # Instancia singleton de configuración settings = Settings()