48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
from pathlib import Path
|
|
from typing import List, Optional, Union
|
|
|
|
from pydantic import AnyHttpUrl, EmailStr, validator
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
# Base Settings
|
|
PROJECT_NAME: str = "User Authentication Service"
|
|
API_V1_STR: str = "/api/v1"
|
|
|
|
# Database Settings
|
|
DB_DIR: Path = Path("/app") / "storage" / "db"
|
|
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
|
|
|
# JWT Settings
|
|
SECRET_KEY: str = "CHANGE_THIS_TO_A_SECURE_SECRET_IN_PRODUCTION"
|
|
ALGORITHM: str = "HS256"
|
|
# 60 minutes * 24 hours * 7 days = 7 days
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7
|
|
|
|
# CORS Settings
|
|
BACKEND_CORS_ORIGINS: List[Union[str, 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)
|
|
|
|
# Email Settings
|
|
EMAILS_FROM_EMAIL: Optional[EmailStr] = None
|
|
EMAILS_FROM_NAME: Optional[str] = None
|
|
|
|
class Config:
|
|
case_sensitive = True
|
|
env_file = ".env"
|
|
|
|
|
|
# Create settings object
|
|
settings = Settings()
|
|
|
|
# Ensure DB directory exists
|
|
settings.DB_DIR.mkdir(parents=True, exist_ok=True)
|