Files
ATLAS/backend/app/core/config.py
ATLAS Admin e59aa2a742 feat: Complete ATLAS system installation and API fixes
## Backend Changes
- Add new API endpoints: combustible, pois, mantenimiento, video, configuracion
- Fix vehiculos endpoint to return paginated response with items array
- Add /vehiculos/all endpoint for non-paginated list
- Add /geocercas/all endpoint
- Add /alertas/configuracion GET/PUT endpoints
- Add /viajes/activos and /viajes/iniciar endpoints
- Add /reportes/stats, /reportes/templates, /reportes/preview endpoints
- Add /conductores/all and /conductores/disponibles endpoints
- Update router.py to include all new modules

## Frontend Changes
- Fix authentication token handling (snake_case vs camelCase)
- Update vehiculosApi.listAll to use /vehiculos/all
- Fix FuelGauge component usage in Combustible page
- Fix chart component exports (named + default exports)
- Update API client for proper token refresh

## Infrastructure
- Rename services from ADAN to ATLAS
- Configure Cloudflare tunnel for atlas.consultoria-as.com
- Update systemd service files
- Configure PostgreSQL with TimescaleDB
- Configure Redis, Mosquitto, Traccar, MediaMTX

## Documentation
- Update installation guides
- Update API reference
- Rename all ADAN references to ATLAS

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 03:04:23 +00:00

178 lines
5.4 KiB
Python

"""
Configuración central de la aplicación.
Utiliza Pydantic BaseSettings para cargar variables de entorno
con validación de tipos y valores por defecto.
"""
from functools import lru_cache
from typing import Any, List, Optional
from pydantic import PostgresDsn, field_validator, model_validator
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
"""Configuración de la aplicación cargada desde variables de entorno."""
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
case_sensitive=False,
extra="ignore",
)
# Aplicación
APP_NAME: str = "Atlas Fleet Monitor"
APP_VERSION: str = "1.0.0"
DEBUG: bool = False
ENVIRONMENT: str = "development"
API_V1_PREFIX: str = "/api/v1"
# Servidor
HOST: str = "0.0.0.0"
PORT: int = 8000
WORKERS: int = 4
# Base de datos PostgreSQL/TimescaleDB
POSTGRES_HOST: str = "localhost"
POSTGRES_PORT: int = 5432
POSTGRES_USER: str = "atlas"
POSTGRES_PASSWORD: str = "atlas_secret"
POSTGRES_DB: str = "atlas_fleet"
DATABASE_URL: Optional[str] = None
DATABASE_POOL_SIZE: int = 20
DATABASE_MAX_OVERFLOW: int = 10
@model_validator(mode="after")
def build_database_url(self) -> "Settings":
"""Construye la URL de conexión a la base de datos."""
if not self.DATABASE_URL:
self.DATABASE_URL = (
f"postgresql+asyncpg://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}"
f"@{self.POSTGRES_HOST}:{self.POSTGRES_PORT}/{self.POSTGRES_DB}"
)
return self
# Redis
REDIS_HOST: str = "localhost"
REDIS_PORT: int = 6379
REDIS_DB: int = 0
REDIS_PASSWORD: Optional[str] = None
REDIS_URL: Optional[str] = None
@model_validator(mode="after")
def build_redis_url(self) -> "Settings":
"""Construye la URL de conexión a Redis."""
if not self.REDIS_URL:
password_part = f":{self.REDIS_PASSWORD}@" if self.REDIS_PASSWORD else ""
self.REDIS_URL = f"redis://{password_part}{self.REDIS_HOST}:{self.REDIS_PORT}/{self.REDIS_DB}"
return self
# Seguridad JWT
SECRET_KEY: str = "your-super-secret-key-change-in-production"
ALGORITHM: str = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
REFRESH_TOKEN_EXPIRE_DAYS: int = 7
# CORS
CORS_ORIGINS: List[str] = ["http://localhost:3000", "http://localhost:5173"]
CORS_ALLOW_CREDENTIALS: bool = True
CORS_ALLOW_METHODS: List[str] = ["*"]
CORS_ALLOW_HEADERS: List[str] = ["*"]
@field_validator("CORS_ORIGINS", mode="before")
@classmethod
def parse_cors_origins(cls, v: Any) -> List[str]:
"""Parsea los orígenes CORS desde string separado por comas."""
if isinstance(v, str):
return [origin.strip() for origin in v.split(",")]
return v
# Traccar Integration
TRACCAR_HOST: str = "localhost"
TRACCAR_PORT: int = 5055
TRACCAR_API_URL: str = "http://localhost:8082/api"
TRACCAR_USERNAME: Optional[str] = None
TRACCAR_PASSWORD: Optional[str] = None
# MediaMTX Video Server
MEDIAMTX_HOST: str = "localhost"
MEDIAMTX_API_PORT: int = 9997
MEDIAMTX_RTSP_PORT: int = 8554
MEDIAMTX_WEBRTC_PORT: int = 8889
# Meshtastic
MESHTASTIC_ENABLED: bool = False
MESHTASTIC_SERIAL_PORT: Optional[str] = None
MESHTASTIC_TCP_HOST: Optional[str] = None
MESHTASTIC_TCP_PORT: int = 4403
# MQTT (para dispositivos IoT)
MQTT_ENABLED: bool = False
MQTT_HOST: str = "localhost"
MQTT_PORT: int = 1883
MQTT_USERNAME: Optional[str] = None
MQTT_PASSWORD: Optional[str] = None
MQTT_TOPIC_LOCATIONS: str = "atlas/locations/#"
MQTT_TOPIC_ALERTS: str = "atlas/alerts/#"
# Email (notificaciones)
SMTP_HOST: str = "localhost"
SMTP_PORT: int = 587
SMTP_USER: Optional[str] = None
SMTP_PASSWORD: Optional[str] = None
SMTP_FROM_EMAIL: str = "noreply@atlas-fleet.com"
SMTP_FROM_NAME: str = "Atlas Fleet Monitor"
SMTP_TLS: bool = True
# Push Notifications (Firebase)
FIREBASE_CREDENTIALS_PATH: Optional[str] = None
FIREBASE_ENABLED: bool = False
# Almacenamiento de archivos
UPLOAD_DIR: str = "/var/lib/atlas/uploads"
MAX_UPLOAD_SIZE_MB: int = 100
ALLOWED_IMAGE_TYPES: List[str] = ["image/jpeg", "image/png", "image/webp"]
ALLOWED_VIDEO_TYPES: List[str] = ["video/mp4", "video/webm"]
# Reportes
REPORTS_DIR: str = "/var/lib/atlas/reports"
REPORT_RETENTION_DAYS: int = 90
# Geocoding
GEOCODING_PROVIDER: str = "nominatim" # nominatim, google, mapbox
GOOGLE_MAPS_API_KEY: Optional[str] = None
MAPBOX_ACCESS_TOKEN: Optional[str] = None
# Alertas y umbrales
ALERT_SPEED_LIMIT_DEFAULT: int = 120 # km/h
ALERT_IDLE_MINUTES: int = 15
ALERT_BATTERY_LOW_PERCENT: int = 20
ALERT_NO_SIGNAL_MINUTES: int = 30
# Limpieza de datos
LOCATION_RETENTION_DAYS: int = 365
ALERT_RETENTION_DAYS: int = 180
VIDEO_RETENTION_DAYS: int = 30
# Logging
LOG_LEVEL: str = "INFO"
LOG_FORMAT: str = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
LOG_FILE: Optional[str] = None
@lru_cache()
def get_settings() -> Settings:
"""
Obtiene la instancia de configuración (singleton cacheado).
Returns:
Settings: Instancia de configuración de la aplicación.
"""
return Settings()
# Instancia global de configuración
settings = get_settings()