Files
mtusi2026lab2/scripts/bootstrap.py
T
Mirariel 370d947132
Application acceptance / acceptance (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
Implement lab 2 PostgreSQL sessions and Redis profile cache
2026-11-19 10:47:21 +03:00

22 lines
869 B
Python

"""Create local synthetic secrets once; never overwrite existing credentials."""
import secrets
from pathlib import Path
root = Path(__file__).resolve().parents[1]
directory = root / 'secrets'
directory.mkdir(exist_ok=True)
password_file = directory / 'db_password'
if not password_file.exists():
with password_file.open('x', encoding='utf-8') as file:
file.write(secrets.token_urlsafe(32))
password = password_file.read_text(encoding='utf-8').strip()
url_file = directory / 'database_url'
if not url_file.exists():
with url_file.open('x', encoding='utf-8') as file:
file.write('postgresql://messenger:' + password + '@db:5432/messenger')
env = root / '.env'
if not env.exists():
with env.open('x', encoding='utf-8') as file:
file.write('SESSION_TTL_SECONDS=3600\n')
print('Local configuration ready; credentials are not printed.')