Coverage for app/config.py: 100%
39 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-10-31 11:18 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-10-31 11:18 +0000
1# svc-auth/config.py
2from pydantic_settings import BaseSettings
3from typing import Optional
6class Settings(BaseSettings):
7 # Auth0 Configuration
8 AUTH0_DOMAIN: str
9 AUTH0_CLIENT_ID: str
10 AUTH0_CLIENT_SECRET: str
11 AUTH0_AUDIENCE: str
12 # The ID-token claim holding the user's platform roles, set by an Auth0
13 # post-login Action from the roles assigned in Auth0
14 # (docs/system/security/auth-flow.md#platform-roles). A token without it
15 # says nothing about roles, and nothing about them changes.
16 AUTH0_ROLES_CLAIM: str = "https://datachainr.com/roles"
18 # Redis Configuration
19 REDIS_URL: str = "redis://redis:6379"
20 REDIS_PASSWORD: Optional[str] = None
22 # Postgres Configuration (durable session history / audit store)
23 POSTGRES_USER: str = "chainr_auth_admin"
24 POSTGRES_PASSWORD: str = "chainr_auth_dev"
25 POSTGRES_HOST: str = "modules-postgres-auth-1"
26 POSTGRES_DB: str = "chainr_auth_dev"
27 RUN_MIGRATIONS: bool = True
29 # Session-tracking tuning
30 # Only persist a session's `last_seen_at` to Postgres at most once per this
31 # many seconds — `/verify` fires on nearly every request, so an unthrottled
32 # write would hammer the DB for no benefit.
33 SESSION_TOUCH_INTERVAL: int = 60
35 # Session-history retention. Ended sessions (logged out / revoked / expired)
36 # whose `ended_at` is older than this many days are permanently deleted by a
37 # periodic background purge. Active sessions are never affected. Keeping IP/
38 # geo history indefinitely is itself a privacy/GDPR concern, so this bounds
39 # it. Set to 0 to disable purging entirely.
40 SESSION_RETENTION_DAYS: int = 90
41 # How often the retention purge runs, in seconds (default once per day).
42 SESSION_PURGE_INTERVAL: int = 86400
44 # Offline IP geolocation. Best-effort: when the MaxMind GeoLite2-City DB is
45 # absent (no license configured) or the IP is private/loopback, location is
46 # simply omitted. No third party ever sees user IPs.
47 GEOIP_DB_PATH: Optional[str] = None
49 # Session Configuration
50 SESSION_SECRET: str
51 SESSION_MAX_AGE: int = 900 # 15 minutes
52 SESSION_COOKIE_NAME: str = "sid"
54 # Application Configuration
55 ENVIRONMENT: str = "development"
56 FRONTEND_URL: str = "http://app.dev.datachainr.com:8000"
57 AUTH_CALLBACK_URL: str = "http://auth.dev.datachainr.com:8000/callback"
58 PUBLIC_URL: str = "http://dev.datachainr.com:8000"
60 # CORS: additional browser origins allowed to call this service with
61 # credentials, beyond FRONTEND_URL / PUBLIC_URL (which are always allowed).
62 # Comma-separated, e.g. "https://preview.datachainr.com". Kept as a plain
63 # string (not list[str]) so it round-trips cleanly through env/SSM without
64 # pydantic's JSON-list decoding.
65 CORS_ALLOWED_ORIGINS: str = ""
67 # Token Configuration
68 TOKEN_REFRESH_THRESHOLD: int = 300 # Refresh if expiring within 5 minutes
69 OAUTH_STATE_TTL: int = 600 # 10 minutes
71 # Security
72 COOKIE_SECURE: bool = False # Set to True in production with HTTPS
73 COOKIE_SAMESITE: str = "lax" # or "strict" for more security
74 COOKIE_DOMAIN: Optional[str] = ".dev.datachainr.com"
76 class Config:
77 env_file = ".env"
78 case_sensitive = True
80 @property
81 def POSTGRES_URL_FULL(self) -> str:
82 return (
83 f"postgresql+psycopg2://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}"
84 f"@{self.POSTGRES_HOST}/{self.POSTGRES_DB}"
85 )
88settings = Settings()