""" YAZ Care Platform - Shared Configuration """ import os from typing import List, Optional import structlog from pydantic import Field from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): """Application settings.""" model_config = SettingsConfigDict( env_file=".env", env_file_encoding="utf-8", case_sensitive=False, ) # Application debug: bool = Field(True) # Default to True for development secret_key: str = Field("dev-secret-key-change-in-production") allowed_hosts: list[str] = Field( [ "localhost", "127.0.0.1", "0.0.0.0", "yaz.ma", "api.yaz.ma", "creators.yaz.ma", "www.yaz.ma", ] ) cors_origins: list[str] = Field(["http://localhost:3000", "http://localhost:8000"]) # Database database_url: str = Field("sqlite:///./data/yaz_care_dev.db") database_pool_size: int = Field(10) # Redis redis_url: str = Field("redis://localhost:6379") # Security jwt_algorithm: str = Field("HS256") jwt_expire_minutes: int = Field(30) password_min_length: int = Field(12) # Encryption encryption_key: str = Field("") # HIPAA Compliance audit_logs_enabled: bool = Field(True) data_retention_days: int = Field(2555) # 7 years # AI/ML ai_models_path: str = Field("./models") ai_inference_timeout: int = Field(30) # External APIs fhir_server_url: str | None = Field(None) dicom_server_url: str | None = Field(None) # Monitoring prometheus_enabled: bool = Field(True) sentry_dsn: str | None = Field(None) def validate_production_secrets(self) -> None: """Reject dev placeholder secrets in production mode.""" if self.debug: return _log = structlog.get_logger("yaz.config") insecure = [] if self.secret_key.startswith("dev-"): insecure.append("SECRET_KEY") if not self.encryption_key or self.encryption_key.startswith("dev-"): insecure.append("ENCRYPTION_KEY") jwt_secret = os.environ.get("JWT_SECRET", "") if jwt_secret.startswith("dev-"): insecure.append("JWT_SECRET") if insecure: msg = f"Insecure dev secrets in production: {', '.join(insecure)}. Set proper values or enable DEBUG mode." _log.critical(msg) raise SystemExit(msg) # Global settings instance _settings: Settings | None = None def get_settings() -> Settings: """Get application settings singleton.""" global _settings if _settings is None: _settings = Settings() # type: ignore[call-arg, call-overload, no-redef] _settings.validate_production_secrets() return _settings