forked from mtusi2026/mtusi2026lab2
ЛР 2 — БПИ-2304 — Саламатин — на 4
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
"""Runtime settings; credential values are never logged."""
|
||||
from dataclasses import dataclass
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def secret(name):
|
||||
return Path(os.environ[name + "_FILE"]).read_text(encoding="utf-8").strip()
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Settings:
|
||||
database_url: str
|
||||
cache_url: str
|
||||
cursor_key: bytes
|
||||
session_ttl: int
|
||||
|
||||
@classmethod
|
||||
def load(cls):
|
||||
ttl = int(os.getenv("SESSION_TTL_SECONDS", "3600"))
|
||||
if not 1 <= ttl <= 604800:
|
||||
raise ValueError("SESSION_TTL_SECONDS must be in 1..604800")
|
||||
if os.getenv("SESSION_STORE", "redis") != "redis":
|
||||
raise ValueError("This deployment uses SESSION_STORE=redis")
|
||||
key = secret("CURSOR_KEY").encode()
|
||||
if len(key) < 32:
|
||||
raise ValueError("Cursor key must contain at least 32 bytes")
|
||||
return cls(secret("DATABASE_URL"), secret("CACHE_URL"), key, ttl)
|
||||
Reference in New Issue
Block a user