forked from mtusi2026/mtusi2026lab3
19 lines
756 B
Python
19 lines
756 B
Python
"""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.")
|