
- Replaced BaseSettings import from pydantic to pydantic-settings - Updated validator to field_validator with mode='before' - Changed Config inner class to model_config dict - Added pydantic-settings to requirements.txt
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
from pathlib import Path
|
|
from typing import List, Union
|
|
|
|
from pydantic import field_validator
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
API_V1_STR: str = "/api/v1"
|
|
PROJECT_NAME: str = "Invoicing API"
|
|
PROJECT_DESCRIPTION: str = "Professional Invoicing API for Freelancers and Small Businesses"
|
|
VERSION: str = "0.1.0"
|
|
|
|
# CORS settings
|
|
BACKEND_CORS_ORIGINS: List[str] = ["*"]
|
|
|
|
@field_validator("BACKEND_CORS_ORIGINS", mode="before")
|
|
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"
|
|
|
|
# JWT settings
|
|
SECRET_KEY: str = "YOUR_SECRET_KEY_HERE_PLEASE_CHANGE_THIS_IN_PRODUCTION"
|
|
ALGORITHM: str = "HS256"
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7 # 7 days
|
|
|
|
# File storage
|
|
STORAGE_DIR: Path = Path("/app") / "storage"
|
|
INVOICE_STORAGE_DIR: Path = STORAGE_DIR / "invoices"
|
|
|
|
# Configure logging
|
|
LOG_LEVEL: str = "INFO"
|
|
|
|
model_config = {
|
|
"case_sensitive": True,
|
|
"env_file": ".env"
|
|
}
|
|
|
|
|
|
# Create all necessary directories
|
|
for dir_path in [Settings().DB_DIR, Settings().INVOICE_STORAGE_DIR]:
|
|
dir_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
settings = Settings() |