43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
import os
|
|
from pathlib import Path
|
|
from typing import List, Union
|
|
|
|
from pydantic import AnyHttpUrl, BaseSettings, EmailStr, validator
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
API_V1_STR: str = "/api/v1"
|
|
SECRET_KEY: str = os.getenv("SECRET_KEY", "your-secret-key-for-development-only")
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8 # 8 days
|
|
|
|
# Server settings
|
|
SERVER_NAME: str = os.getenv("SERVER_NAME", "Small Business Inventory")
|
|
SERVER_HOST: AnyHttpUrl = os.getenv("SERVER_HOST", "http://localhost")
|
|
PROJECT_NAME: str = "Small Business Inventory Management System"
|
|
|
|
# Database settings
|
|
DB_DIR = Path("/app") / "storage" / "db"
|
|
DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
|
|
|
# CORS settings
|
|
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)
|
|
|
|
# Superuser settings
|
|
FIRST_SUPERUSER: EmailStr = os.getenv("FIRST_SUPERUSER", "admin@example.com")
|
|
FIRST_SUPERUSER_PASSWORD: str = os.getenv("FIRST_SUPERUSER_PASSWORD", "admin")
|
|
|
|
class Config:
|
|
case_sensitive = True
|
|
env_file = ".env"
|
|
|
|
|
|
settings = Settings() |