forked from mtusi2026/mtusi2026lab4
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import socket
|
|
from pathlib import Path
|
|
|
|
|
|
def _get_val(env_name: str, file_env_name: str | None = None, default: str = "") -> str:
|
|
if file_env_name and file_env_name in os.environ:
|
|
file_path = Path(os.environ[file_env_name])
|
|
if file_path.is_file():
|
|
return file_path.read_text(encoding="utf-8").strip()
|
|
return os.getenv(env_name, default)
|
|
|
|
|
|
APP_HOST: str = os.getenv("APP_HOST", "0.0.0.0")
|
|
APP_PORT: int = int(os.getenv("APP_PORT", "8080"))
|
|
APP_ENV: str = os.getenv("APP_ENV", "lab")
|
|
LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO")
|
|
|
|
SESSION_TTL_SECONDS: int = int(os.getenv("SESSION_TTL_SECONDS", "3600"))
|
|
SESSION_STORE: str = os.getenv("SESSION_STORE", "redis").lower()
|
|
INSTANCE_ID: str = os.getenv("INSTANCE_ID") or socket.gethostname() or "api-1"
|
|
IDEMPOTENCY_TTL_SECONDS: int = int(os.getenv("IDEMPOTENCY_TTL_SECONDS", "86400"))
|
|
|
|
DATABASE_URL: str = _get_val(
|
|
"DATABASE_URL",
|
|
"DATABASE_URL_FILE",
|
|
"postgresql://postgres:postgres@postgres:5432/messenger",
|
|
)
|
|
|
|
CACHE_URL: str = _get_val(
|
|
"CACHE_URL",
|
|
"CACHE_URL_FILE",
|
|
"redis://redis:6379/0",
|
|
)
|