Files
urllists/config.py
2025-11-30 12:53:36 +00:00

50 lines
1.2 KiB
Python

"""Application configuration from environment variables."""
import os
from functools import lru_cache
from typing import List
import json
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
"""Application settings from environment variables."""
# JWT & Security
SECRET_KEY: str = "your-super-secret-key-change-this-in-production"
TOKEN_LIFETIME: int = 3600 # 1 hour
# Database
DATABASE_URL: str = "sqlite+aiosqlite:///./sql_app.db"
# App Info
APP_NAME: str = "URL List Manager"
DEBUG: bool = False
# CORS
CORS_ORIGINS: str = '["http://localhost:3000", "http://localhost:8000"]'
# Registration
REGISTRATION_ENABLED: bool = False
# MFA
MFA_ENABLED: bool = True
MFA_ISSUER: str = "URL List Manager"
class Config:
env_file = ".env"
case_sensitive = False
@property
def cors_origins_list(self) -> List[str]:
"""Parse CORS origins from JSON string."""
try:
return json.loads(self.CORS_ORIGINS)
except (json.JSONDecodeError, TypeError):
return ["http://localhost:8000"]
@lru_cache()
def get_settings() -> Settings:
"""Get cached settings instance."""
return Settings()