ЛР 2: PostgreSQL и постоянные сессии — Гавриленко БПИ2303, на 3

This commit is contained in:
2026-11-13 01:27:52 +03:00
parent 65003b6119
commit 40bcd42aa3
19 changed files with 682 additions and 31 deletions
+25
View File
@@ -0,0 +1,25 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
python3 - <<'PY'
import os
import secrets
from pathlib import Path
os.umask(0o077)
root = Path('secrets')
root.mkdir(exist_ok=True)
password_file = root / 'db_password'
if not password_file.exists():
password_file.write_text(secrets.token_hex(32))
password = password_file.read_text().strip()
url = root / 'database_url'
if not url.exists():
from urllib.parse import quote
url.write_text('postgresql://messenger:' + quote(password, safe='') + '@db:5432/messenger')
# Private parent directory protects files on the host; API UID must read its mount.
url.chmod(0o644)
if not Path('.env').exists():
Path('.env').write_text('HOST_PORT=8082\nSESSION_TTL_SECONDS=3600\n')
print('Local secrets and .env ready (existing files preserved)')
PY