Реализовать lab2: PostgreSQL и постоянные Bearer-сессии
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
Надежда Карпова
2026-11-05 01:43:30 +03:00
parent 65003b6119
commit 3daebda0cb
40 changed files with 4208 additions and 20 deletions
+11
View File
@@ -0,0 +1,11 @@
"""Save real command output, preserving the exit code. Do not use with secret-printing commands."""
import datetime,subprocess,sys
from pathlib import Path
if len(sys.argv)<4 or sys.argv[2]!='--':
raise SystemExit('Usage: python3 scripts/capture.py evidence/name.txt -- command args...')
command=sys.argv[3:]
p=subprocess.run(command,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
text='UTC: '+datetime.datetime.now(datetime.timezone.utc).isoformat()+'\nCommand: '+' '.join(command)+'\n'+p.stdout+'\nExit code: '+str(p.returncode)+'\n'
Path(sys.argv[1]).write_text(text)
print(text,end='')
raise SystemExit(p.returncode)
+16
View File
@@ -0,0 +1,16 @@
"""Create local synthetic credentials without printing or replacing existing ones."""
import secrets
from pathlib import Path
root=Path(__file__).resolve().parents[1]
folder=root/'secrets'
folder.mkdir(mode=0o700,exist_ok=True)
p=folder/'db_password'; d=folder/'database_url'
if p.exists()!=d.exists():
raise SystemExit('Incomplete secrets: restore the missing file; existing credentials were not changed')
if not p.exists():
password=secrets.token_hex(32)
# Docker secret source directory is private; files must be readable by container UIDs.
p.write_text(password+'\n')
d.write_text('postgresql://messenger:'+password+'@db:5432/messenger\n')
p.chmod(0o644); d.chmod(0o644)
print('Local secret files ready (values hidden). Do not commit secrets/.')
+5
View File
@@ -0,0 +1,5 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
# Restart all three services and retain the named PostgreSQL volume.
docker compose restart db cache api