import secrets from typing import List, Union from pydantic import AnyHttpUrl, validator from pydantic_settings import BaseSettings class Settings(BaseSettings): API_V1_STR: str = "/api/v1" PROJECT_NAME: str = "SimpleTodoApp" # Security SECRET_KEY: str = secrets.token_urlsafe(32) ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8 # 8 days # CORS BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = [] @validator("BACKEND_CORS_ORIGINS", pre=True) def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]: if isinstance(v, str) and not v.startswith("["): return [i.strip() for i in v.split(",")] elif isinstance(v, (list, str)): return v raise ValueError(v) settings = Settings()