forked from mtusi2026/mtusi2026lab2
2: PostgreSQL, вход Basic -> Bearer, сессии в Redis
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import secrets
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SECRETS = ROOT / "secrets"
|
||||
|
||||
|
||||
def write(name: str, value: str) -> None:
|
||||
with open(SECRETS / name, "w", encoding="utf-8", newline="") as file:
|
||||
file.write(value)
|
||||
(SECRETS / name).chmod(0o644)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if (SECRETS / "postgres_password").exists():
|
||||
print("secrets/ already exists, nothing changed.")
|
||||
return
|
||||
SECRETS.mkdir(exist_ok=True)
|
||||
db_password = secrets.token_hex(24)
|
||||
redis_password = secrets.token_hex(24)
|
||||
|
||||
write("postgres_password", db_password)
|
||||
write("database_url", f"postgresql://messenger:{db_password}@postgres:5432/messenger")
|
||||
write("cache_url", f"redis://:{redis_password}@redis:6379/0")
|
||||
write("redis_auth", f"requirepass {redis_password}\n")
|
||||
print("Created secrets/: postgres_password, database_url, cache_url, redis_auth (values are not printed).")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,7 @@
|
||||
@echo off
|
||||
rem Restart hook for tests/resilience.py on Windows (same as scripts/restart.sh).
|
||||
rem Python on Windows cannot start .sh files directly (WinError 193), a .cmd file works.
|
||||
rem Restarts all containers of the stand: api, postgres, redis. Volumes are kept (no down -v).
|
||||
cd /d "%~dp0.."
|
||||
docker compose restart || exit /b 1
|
||||
exit /b 0
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
docker compose restart
|
||||
Reference in New Issue
Block a user