5ec1fc9b05
B1: Remove duplicate get_redis() — singleton no longer overwritten B2: Plugin routes now enforce activation status via require_active_plugin() B3: Fix UploadFile ForwardRef error — remove functools.wraps from wrap_plugin_route B4: DMS upload uses true streaming via save_stream() instead of RAM accumulation B5: Worker on_startup registers plugin event handlers + webhook dispatcher B6: Implement send_password_reset_email job, remove raw token logging B7: Webhook SSRF protection (IP validation, no redirects), secret removed from response B8: RLS repair migration 0044 + separate crm_runtime DB user (NOSUPERUSER, NOBYPASSRLS) B9: Fix .env.docker.example AUTH_SECRET → SECRET_KEY B10: Remove Redis default password, remove exposed DB/Redis ports Also: add frontend_url to config, add SMTP settings to .env.docker.example, update prestart.sh to use MIGRATION_DATABASE_URL for alembic.
96 lines
3.0 KiB
Python
96 lines
3.0 KiB
Python
"""Application configuration via Pydantic Settings."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from functools import lru_cache
|
|
from typing import Literal
|
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""Application settings loaded from environment variables."""
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env",
|
|
env_file_encoding="utf-8",
|
|
case_sensitive=False,
|
|
extra="ignore",
|
|
)
|
|
|
|
# Environment
|
|
environment: Literal["development", "production", "testing"] = "development"
|
|
log_level: str = "INFO"
|
|
|
|
# Database
|
|
database_url: str = "postgresql+asyncpg://leocrm:leocrm@localhost:5432/leocrm_test"
|
|
db_pool_size: int = 10
|
|
db_max_overflow: int = 20
|
|
db_echo: bool = False
|
|
|
|
# Redis
|
|
redis_url: str = "redis://localhost:6379/0"
|
|
session_ttl_seconds: int = 28800 # 8 hours
|
|
|
|
# Auth
|
|
bcrypt_rounds: int = 12
|
|
session_cookie_name: str = "leocrm_session"
|
|
session_cookie_secure: bool = True # Secure by default — set to False only for local HTTP development
|
|
session_cookie_samesite: str = "strict"
|
|
session_cookie_httponly: bool = True
|
|
password_reset_expiry_hours: int = 1
|
|
|
|
# Storage
|
|
storage_path: str = "/data/storage"
|
|
|
|
# SMTP
|
|
smtp_host: str = "localhost"
|
|
smtp_port: int = 587
|
|
smtp_username: str | None = None
|
|
smtp_password: str | None = None
|
|
smtp_from_email: str = "noreply@leocrm.local"
|
|
smtp_use_tls: bool = True
|
|
|
|
# Secret Key (for signing, sessions, etc.)
|
|
secret_key: str = "change-me-in-production-use-a-secure-random-string"
|
|
|
|
# CORS
|
|
cors_origins: str = "http://localhost:5173,http://localhost:3000"
|
|
|
|
# Frontend URL for email links (password reset, invitations, etc.)
|
|
frontend_url: str = "http://localhost:5173"
|
|
|
|
# Rate Limiting
|
|
rate_limit_login_max: int = 5
|
|
rate_limit_login_window: int = 900 # 15 min
|
|
rate_limit_reset_max: int = 3
|
|
rate_limit_reset_window: int = 3600 # 1 hour
|
|
rate_limit_reset_confirm_max: int = 5
|
|
rate_limit_reset_confirm_window: int = 3600 # 1 hour
|
|
rate_limit_general_max: int = 60
|
|
rate_limit_general_window: int = 60 # 1 min
|
|
|
|
@property
|
|
def cors_origin_list(self) -> list[str]:
|
|
"""Parse comma-separated CORS origins into a list."""
|
|
return [o.strip() for o in self.cors_origins.split(",") if o.strip()]
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
"""Get cached settings instance."""
|
|
s = Settings()
|
|
# Production safety checks
|
|
if s.environment == "production":
|
|
if not s.session_cookie_secure:
|
|
raise RuntimeError("SESSION_COOKIE_SECURE must be True in production")
|
|
if s.secret_key == "change-me-in-production-use-a-secure-random-string":
|
|
raise RuntimeError("SECRET_KEY must be changed from default in production")
|
|
if s.storage_path == "/tmp":
|
|
raise RuntimeError("STORAGE_PATH must not be /tmp in production")
|
|
return s
|
|
|
|
|
|
# Module-level singleton for backward-compatible imports
|
|
settings = get_settings()
|