Files
mtusi2026lab2/src/config.py
T

24 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
from pathlib import Path
def _read_secret(file_var: str, direct_var: str) -> str:
"""Секрет из файла (DATABASE_URL_FILE), с запасным вариантом из переменной окружения."""
path = os.environ.get(file_var)
if path:
return Path(path).read_text().strip()
return os.environ.get(direct_var, "")
DATABASE_URL = _read_secret("DATABASE_URL_FILE", "DATABASE_URL")
SESSION_TTL_SECONDS = int(os.environ.get("SESSION_TTL_SECONDS", "3600"))
DB_POOL_MIN = int(os.environ.get("DB_POOL_MIN", "2"))
DB_POOL_MAX = int(os.environ.get("DB_POOL_MAX", "10"))
DB_CONNECT_TIMEOUT = float(os.environ.get("DB_CONNECT_TIMEOUT", "5"))
DB_COMMAND_TIMEOUT = float(os.environ.get("DB_COMMAND_TIMEOUT", "5"))
MIGRATIONS_DIR = Path(os.environ.get("MIGRATIONS_DIR", Path(__file__).resolve().parent.parent / "migrations"))
CACHE_URL = _read_secret("CACHE_URL_FILE", "CACHE_URL")
CACHE_TTL_SECONDS = int(os.environ.get("CACHE_TTL_SECONDS", "60"))
CACHE_TIMEOUT = float(os.environ.get("CACHE_TIMEOUT", "0.5"))