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

This commit is contained in:
2026-11-13 13:27:43 +03:00
parent 0ab3a341aa
commit fd086f679e
30 changed files with 1450 additions and 24 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.")