import secrets from typing import Any, Dict, List, Optional, Union from pydantic import AnyHttpUrl, BaseSettings, validator, EmailStr, HttpUrl class Settings(BaseSettings): API_V1_STR: str = "/api/v1" SQLALCHEMY_DATABASE_URI: str = "sqlite:///./floorball.db" SECRET_KEY: str = secrets.token_urlsafe(32) # 60 minutes * 24 hours * 8 days = 8 days ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8 SERVER_NAME: str = "localhost" SERVER_HOST: AnyHttpUrl = "http://localhost" # BACKEND_CORS_ORIGINS is a JSON-formatted list of origins # e.g: '["http://localhost", "http://localhost:4200", "http://localhost:3000", \ # "http://localhost:8080", "http://local.dockertoolbox.tiangolo.com"]' 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) PROJECT_NAME: str = "Floorball stats" SENTRY_DSN: Optional[HttpUrl] = "" @validator("SENTRY_DSN", pre=True) def sentry_dsn_can_be_blank(cls, v: str) -> Optional[str]: if len(v) == 0: return None return v EMAIL_TEST_USER: EmailStr = "test@example.com" # type: ignore FIRST_SUPERUSER: EmailStr = "test@example.com" FIRST_SUPERUSER_PASSWORD: str = "hej" USERS_OPEN_REGISTRATION: bool = False class Config: case_sensitive = True settings = Settings()