86 lines
2.2 KiB
Python
86 lines
2.2 KiB
Python
from pydantic_settings import BaseSettings
|
|
from datetime import timedelta
|
|
|
|
class Settings(BaseSettings):
|
|
# =========================
|
|
# ENVIRONMENT
|
|
# =========================
|
|
ENV: str
|
|
|
|
# =========================
|
|
# DATABASE
|
|
# =========================
|
|
DATABASE_HOST: str
|
|
DATABASE_PORT: int
|
|
DATABASE_USER: str
|
|
DATABASE_PASSWORD: str
|
|
DATABASE_NAME: str
|
|
|
|
# =========================
|
|
# FASTAPI
|
|
# =========================
|
|
DEBUG: bool = True
|
|
APP_TITLE: str = "MokPyo API"
|
|
APP_VERSION: str = "1.0.0"
|
|
APP_DESCRIPTION: str = "MokPyo"
|
|
APP_DOMAIN: str = "localhost"
|
|
STATIC_DIR: str = "app/static"
|
|
|
|
# =========================
|
|
# SERVER
|
|
# =========================
|
|
HOST: str = "0.0.0.0"
|
|
PORT: int = 8000
|
|
UVICORN_WORKERS: int = 4
|
|
|
|
# =========================
|
|
# SECURITY / AUTH
|
|
# =========================
|
|
SECRET_KEY: str
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
|
|
ALGORITHM: str = "HS256"
|
|
USE_SSL: bool = False
|
|
|
|
# =========================
|
|
# EMAIL (optionnel)
|
|
# =========================
|
|
SMTP_HOST: str = ""
|
|
SMTP_PORT: int = 587
|
|
SMTP_USER: str = ""
|
|
SMTP_PASSWORD: str = ""
|
|
EMAIL_FROM: str = ""
|
|
|
|
# =========================
|
|
# LOGGING
|
|
# =========================
|
|
LOG_LEVEL: str = "INFO"
|
|
LOG_FILE: str = "logs/app.log"
|
|
|
|
# =========================
|
|
# UPLOADS / FILES
|
|
# =========================
|
|
MAX_UPLOAD_SIZE: int = 10_485_760 # 10 MB
|
|
|
|
# =========================
|
|
# ORJSON
|
|
# =========================
|
|
ORJSON_STRICT: bool = True
|
|
|
|
@property
|
|
def database_url(self) -> str:
|
|
return f"mysql+<driver>://{self.DATABASE_USER}:{self.DATABASE_PASSWORD}@{self.DATABASE_HOST}:{self.DATABASE_PORT}/{self.DATABASE_NAME}"
|
|
|
|
@property
|
|
def app_url(self) -> str:
|
|
return f"{'https' if settings.USE_SSL else 'http'}://{settings.APP_DOMAIN}{':' + str(settings.PORT) if (settings.PORT != 80 and settings.ENV == 'dev') else ''}"
|
|
|
|
@property
|
|
def access_token_expire(self) -> timedelta:
|
|
return timedelta(minutes=self.ACCESS_TOKEN_EXPIRE_MINUTES)
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
env_file_encoding = "utf-8"
|
|
|
|
# Instance globale
|
|
settings = Settings() |