from typing import List, Union from pathlib import Path from pydantic import AnyHttpUrl, validator from pydantic_settings import BaseSettings class Settings(BaseSettings): API_V1_STR: str = "/api/v1" PROJECT_NAME: str = "User Authentication Service" PROJECT_DESCRIPTION: str = "API service for user authentication" PROJECT_VERSION: str = "0.1.0" # Secret key for JWT token and other security mechanisms SECRET_KEY: str = "YOUR_SUPER_SECRET_KEY_CHANGE_THIS_IN_PRODUCTION" # 60 minutes * 24 hours * 8 days = 8 days in minutes ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8 # 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) # Database DB_DIR: Path = Path("/app/storage/db") SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite" # Token related TOKEN_URL: str = f"{API_V1_STR}/auth/login" class Config: case_sensitive = True env_file = ".env" # Create the DB directory if it doesn't exist Settings().DB_DIR.mkdir(parents=True, exist_ok=True) settings = Settings()