forked from mtusi2026/mtusi2026lab3
30 lines
1.4 KiB
Python
30 lines
1.4 KiB
Python
import os
|
|
import re
|
|
import socket
|
|
import uuid
|
|
|
|
APP_HOST = os.getenv("APP_HOST", "0.0.0.0")
|
|
APP_PORT = int(os.getenv("APP_PORT", "8080"))
|
|
INSTANCE_ID = os.getenv("INSTANCE_ID", socket.gethostname() or uuid.uuid4().hex[:12])
|
|
SESSION_TTL_SECONDS = int(os.getenv("SESSION_TTL_SECONDS", "3600"))
|
|
IDEMPOTENCY_TTL_SECONDS = int(os.getenv("IDEMPOTENCY_TTL_SECONDS", "86400"))
|
|
DB_STATEMENT_TIMEOUT_MS = int(os.getenv("DB_STATEMENT_TIMEOUT_MS", "5000"))
|
|
DB_LOCK_TIMEOUT_MS = int(os.getenv("DB_LOCK_TIMEOUT_MS", "2000"))
|
|
DB_POOL_MAX_SIZE = int(os.getenv("DB_POOL_MAX_SIZE", "16"))
|
|
DB_POOL_TIMEOUT_SECONDS = float(os.getenv("DB_POOL_TIMEOUT_SECONDS", "5"))
|
|
MAX_INFLIGHT_REQUESTS = int(os.getenv("MAX_INFLIGHT_REQUESTS", "128"))
|
|
MAX_REQUEST_BODY_BYTES = int(os.getenv("MAX_REQUEST_BODY_BYTES", "1048576"))
|
|
USER_RE = re.compile(r"^[a-z0-9_]{3,32}$")
|
|
IDEMPOTENCY_KEY_RE = re.compile(r"^[A-Za-z0-9._:-]{1,128}$")
|
|
|
|
if SESSION_TTL_SECONDS < 1:
|
|
raise RuntimeError("SESSION_TTL_SECONDS must be positive")
|
|
if IDEMPOTENCY_TTL_SECONDS < 86400:
|
|
raise RuntimeError("IDEMPOTENCY_TTL_SECONDS must be at least 86400")
|
|
if DB_STATEMENT_TIMEOUT_MS < 1 or DB_LOCK_TIMEOUT_MS < 1:
|
|
raise RuntimeError("Database timeouts must be positive")
|
|
if DB_POOL_MAX_SIZE < 1 or DB_POOL_TIMEOUT_SECONDS <= 0:
|
|
raise RuntimeError("Database pool settings must be positive")
|
|
if MAX_INFLIGHT_REQUESTS < 1 or MAX_REQUEST_BODY_BYTES < 1:
|
|
raise RuntimeError("HTTP limits must be positive")
|