ЛР 2 — БПИ2303 — Щербаков — на 3

This commit is contained in:
2026-10-29 18:44:39 +03:00
parent 65003b6119
commit 6c1e93bb09
24 changed files with 1196 additions and 37 deletions
+18
View File
@@ -0,0 +1,18 @@
"""Generate local synthetic credentials without printing or overwriting them."""
from pathlib import Path
import secrets
root = Path(__file__).resolve().parents[1]
directory = root / "secrets"
directory.mkdir(exist_ok=True)
password_file = directory / "postgres_password"
if not password_file.exists():
password_file.write_text(secrets.token_hex(32), encoding="ascii")
url = directory / "database_url"
if not url.exists():
password = password_file.read_text(encoding="ascii").strip()
url.write_text(f"postgresql://messenger:{password}@postgres:5432/messenger", encoding="ascii")
env = root / ".env"
if not env.exists():
env.write_bytes((root / ".env.example").read_bytes())
print("Local .env and secrets ready; existing files preserved.")