44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
"""Application configuration module."""
|
|
import os
|
|
from pathlib import Path
|
|
from typing import Any, Dict, List, Optional
|
|
|
|
from pydantic import AnyHttpUrl, EmailStr, Field, validator
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""Application settings."""
|
|
|
|
# Base settings
|
|
PROJECT_NAME: str = "User Authentication Service"
|
|
PROJECT_DESCRIPTION: str = "FastAPI service for user authentication"
|
|
VERSION: str = "0.1.0"
|
|
API_V1_STR: str = "/api/v1"
|
|
DEBUG: bool = False
|
|
HOST: str = "0.0.0.0"
|
|
PORT: int = 8000
|
|
|
|
# Security settings
|
|
SECRET_KEY: str = os.getenv("SECRET_KEY", "CHANGE_THIS_SECRET_KEY_IN_PRODUCTION")
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", "30"))
|
|
ALGORITHM: str = "HS256"
|
|
|
|
# Super admin settings (for first user creation)
|
|
FIRST_SUPERUSER_EMAIL: Optional[EmailStr] = os.getenv("FIRST_SUPERUSER_EMAIL")
|
|
FIRST_SUPERUSER_PASSWORD: Optional[str] = os.getenv("FIRST_SUPERUSER_PASSWORD")
|
|
|
|
# CORS settings
|
|
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
|
|
|
|
@validator("BACKEND_CORS_ORIGINS", pre=True)
|
|
def assemble_cors_origins(cls, v: Any) -> List[str]:
|
|
"""Parse and validate CORS origins."""
|
|
if isinstance(v, str) and not v.startswith("["):
|
|
return [i.strip() for i in v.split(",")]
|
|
if isinstance(v, (list, str)):
|
|
return v
|
|
raise ValueError(v)
|
|
|
|
|
|
settings = Settings() |