44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
from pathlib import Path
|
|
from typing import Any, List
|
|
|
|
from pydantic import validator
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
PROJECT_NAME: str = "User Authentication Service"
|
|
PROJECT_DESCRIPTION: str = "A FastAPI service for user authentication"
|
|
PROJECT_VERSION: str = "0.1.0"
|
|
|
|
# CORS
|
|
BACKEND_CORS_ORIGINS: List[str] = ["*"]
|
|
|
|
@validator("BACKEND_CORS_ORIGINS", pre=True)
|
|
def assemble_cors_origins(cls, v: Any) -> List[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"
|
|
|
|
# JWT
|
|
SECRET_KEY: str = "CHANGEME_SECRET_KEY_CHANGEME"
|
|
ALGORITHM: str = "HS256"
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env",
|
|
env_file_encoding="utf-8",
|
|
case_sensitive=True,
|
|
extra="ignore"
|
|
)
|
|
|
|
|
|
settings = Settings()
|
|
|
|
# Ensure the database directory exists
|
|
settings.DB_DIR.mkdir(parents=True, exist_ok=True) |