83 lines
3.5 KiB
Python
83 lines
3.5 KiB
Python
import os
|
|
import secrets
|
|
from pathlib import Path
|
|
from typing import List, Union, Optional, Annotated
|
|
|
|
from pydantic import EmailStr, field_validator, Field
|
|
from pydantic_settings import BaseSettings
|
|
from pydantic.functional_validators import BeforeValidator
|
|
|
|
# Debug flag
|
|
DEBUG: bool = os.environ.get("DEBUG", "False").lower() == "true"
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
# Project settings
|
|
PROJECT_NAME: str = "Deft Trade"
|
|
PROJECT_DESCRIPTION: str = "DeFi Trading Simulation Platform"
|
|
VERSION: str = "0.1.0"
|
|
API_V1_STR: str = "/api/v1"
|
|
|
|
# Security settings
|
|
SECRET_KEY: str = os.environ.get("SECRET_KEY") or secrets.token_urlsafe(32)
|
|
JWT_SECRET_KEY: str = os.environ.get("JWT_SECRET_KEY") or secrets.token_urlsafe(32)
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = int(os.environ.get("ACCESS_TOKEN_EXPIRE_MINUTES", 30))
|
|
REFRESH_TOKEN_EXPIRE_DAYS: int = int(os.environ.get("REFRESH_TOKEN_EXPIRE_DAYS", 7))
|
|
ALGORITHM: str = "HS256"
|
|
|
|
# Debug flag
|
|
DEBUG: bool = DEBUG
|
|
|
|
# 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
|
|
# Use relative path for local development
|
|
DB_DIR: Path = Path("./projects/defitradingsimulationplatformbackend-9xewa6/app/storage/db")
|
|
|
|
# Email settings
|
|
EMAILS_ENABLED: bool = os.environ.get("EMAILS_ENABLED", "False").lower() == "true"
|
|
SMTP_TLS: bool = os.environ.get("SMTP_TLS", "True").lower() == "true"
|
|
SMTP_PORT: Optional[int] = int(os.environ.get("SMTP_PORT", 587)) if os.environ.get("SMTP_PORT") else None
|
|
SMTP_HOST: Optional[str] = os.environ.get("SMTP_HOST")
|
|
SMTP_USER: Optional[str] = os.environ.get("SMTP_USER")
|
|
SMTP_PASSWORD: Optional[str] = os.environ.get("SMTP_PASSWORD")
|
|
EMAILS_FROM_EMAIL: Optional[str] = os.environ.get("EMAILS_FROM_EMAIL")
|
|
EMAILS_FROM_NAME: Optional[str] = os.environ.get("EMAILS_FROM_NAME")
|
|
|
|
# File upload
|
|
UPLOAD_DIR: Path = Path("./projects/defitradingsimulationplatformbackend-9xewa6/app/storage/uploads")
|
|
KYC_UPLOAD_DIR: Path = Path("./projects/defitradingsimulationplatformbackend-9xewa6/app/storage/kyc")
|
|
DEPOSIT_PROOFS_DIR: Path = Path("./projects/defitradingsimulationplatformbackend-9xewa6/app/storage/deposit_proofs")
|
|
MAX_UPLOAD_SIZE: int = int(os.environ.get("MAX_UPLOAD_SIZE", 5 * 1024 * 1024)) # 5 MB default
|
|
|
|
# Admin default settings
|
|
ADMIN_EMAIL: str = os.environ.get("ADMIN_EMAIL", "admin@defttrade.com")
|
|
ADMIN_PASSWORD: str = os.environ.get("ADMIN_PASSWORD", "change-me-please")
|
|
|
|
# 2FA settings
|
|
TWO_FACTOR_REQUIRED: bool = os.environ.get("TWO_FACTOR_REQUIRED", "False").lower() == "true"
|
|
|
|
# Bot simulation settings
|
|
BOT_SIMULATION_INTERVAL: int = int(os.environ.get("BOT_SIMULATION_INTERVAL", 60)) # Seconds
|
|
|
|
# Transaction settings
|
|
MIN_DEPOSIT_AMOUNT: float = float(os.environ.get("MIN_DEPOSIT_AMOUNT", 10.0))
|
|
MIN_WITHDRAWAL_AMOUNT: float = float(os.environ.get("MIN_WITHDRAWAL_AMOUNT", 10.0))
|
|
WITHDRAWAL_FEE_PERCENTAGE: float = float(os.environ.get("WITHDRAWAL_FEE_PERCENTAGE", 1.0))
|
|
|
|
model_config = {
|
|
"case_sensitive": True,
|
|
"env_file": ".env",
|
|
}
|
|
|
|
|
|
settings = Settings() |