feat(lab2): PostgreSQL 18 persistence, Argon2id auth, Redis 7.4 sessions & cache, Grade 5 tracks
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
@echo off
|
||||
cd /d "%~dp0\.."
|
||||
if exist .env (
|
||||
docker compose --env-file .env restart postgres redis api
|
||||
) else (
|
||||
docker compose restart postgres redis api
|
||||
)
|
||||
exit /b %ERRORLEVEL%
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
||||
ROOT_DIR="$(dirname -- "$SCRIPT_DIR")"
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
if [ -f .env ]; then
|
||||
docker compose --env-file .env restart postgres redis api
|
||||
else
|
||||
docker compose restart postgres redis api
|
||||
fi
|
||||
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Helper script to populate synthetic demo data for Lab 2 defense in Swagger UI."""
|
||||
import base64
|
||||
import json
|
||||
import sys
|
||||
import urllib.request
|
||||
import uuid
|
||||
|
||||
BASE_URL = sys.argv[1] if len(sys.argv) > 1 else "http://localhost:8080"
|
||||
|
||||
|
||||
def req(method, path, body=None, headers=None):
|
||||
h = {"Accept": "application/json"}
|
||||
data = None
|
||||
if body is not None:
|
||||
data = json.dumps(body).encode("utf-8")
|
||||
h["Content-Type"] = "application/json"
|
||||
if headers:
|
||||
h.update(headers)
|
||||
r = urllib.request.Request(BASE_URL + path, data=data, headers=h, method=method)
|
||||
with urllib.request.urlopen(r, timeout=10) as resp:
|
||||
raw = resp.read()
|
||||
return json.loads(raw.decode("utf-8")) if raw else None
|
||||
|
||||
|
||||
def main():
|
||||
suffix = uuid.uuid4().hex[:6]
|
||||
alice_username = f"alice_{suffix}"
|
||||
bob_username = f"bob_{suffix}"
|
||||
password = "DemoPassword-2026!"
|
||||
|
||||
alice = req("POST", "/api/v1/users", {
|
||||
"username": alice_username,
|
||||
"display_name": "Alice Zamorskaya",
|
||||
"password": password,
|
||||
})
|
||||
bob = req("POST", "/api/v1/users", {
|
||||
"username": bob_username,
|
||||
"display_name": "Bob Bobrov",
|
||||
"password": password,
|
||||
})
|
||||
|
||||
alice_basic = base64.b64encode(f"{alice_username}:{password}".encode("utf-8")).decode("ascii")
|
||||
bob_basic = base64.b64encode(f"{bob_username}:{password}".encode("utf-8")).decode("ascii")
|
||||
|
||||
alice_sess = req("POST", "/api/v1/auth/sessions", headers={"Authorization": f"Basic {alice_basic}"})
|
||||
bob_sess = req("POST", "/api/v1/auth/sessions", headers={"Authorization": f"Basic {bob_basic}"})
|
||||
|
||||
alice_bearer = {"Authorization": f"Bearer {alice_sess['token']}"}
|
||||
bob_bearer = {"Authorization": f"Bearer {bob_sess['token']}"}
|
||||
|
||||
chat = req("POST", "/api/v1/chats", {
|
||||
"title": "Lab 2 Defense Chat",
|
||||
"member_ids": [alice["id"], bob["id"]],
|
||||
}, headers=alice_bearer)
|
||||
|
||||
req("POST", f"/api/v1/chats/{chat['id']}/messages", {
|
||||
"text": "Hello Bob! Stored in PostgreSQL 18 and cached in Redis 7.4.",
|
||||
}, headers=alice_bearer)
|
||||
req("POST", f"/api/v1/chats/{chat['id']}/messages", {
|
||||
"text": "Hi Alice! Authenticated via Bearer session token.",
|
||||
}, headers=bob_bearer)
|
||||
|
||||
print("=== LAB 2 DEMO DATA CREATED ===")
|
||||
print(f"Swagger UI: {BASE_URL}/docs")
|
||||
print(f"Password: {password}")
|
||||
print(f"Alice Username: {alice_username}")
|
||||
print(f"Alice User ID: {alice['id']}")
|
||||
print(f"Alice Token: {alice_sess['token']}")
|
||||
print(f"Bob Username: {bob_username}")
|
||||
print(f"Bob User ID: {bob['id']}")
|
||||
print(f"Bob Token: {bob_sess['token']}")
|
||||
print(f"Chat ID: {chat['id']}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user