#!/usr/bin/env python3 """Bootstrap local TLS, start the lab7 Compose stack and run public checks.""" import argparse, subprocess, time, urllib.request, ssl BASE = "https://127.0.0.1:8443" CA = "certs/ca.crt" def run(*args): print("$", " ".join(args), flush=True); subprocess.run(args, check=True) def ready(): ctx = ssl.create_default_context(cafile=CA) for _ in range(120): try: with urllib.request.urlopen(BASE + "/health/ready", context=ctx, timeout=2) as r: if r.status == 200: print("READY", flush=True); return except Exception: time.sleep(1) raise SystemExit("HTTPS API не стал ready") def main(): p = argparse.ArgumentParser(); p.add_argument("--full", action="store_true"); p.add_argument("--load", action="store_true"); p.add_argument("--down", action="store_true"); p.add_argument("--no-build", action="store_true"); a = p.parse_args() c = ("docker", "compose", "--env-file", ".env") if a.down: subprocess.run(c + ("down",), check=False); return run("python3", "scripts/bootstrap_tls.py") run(*c, "up", *(()) if a.no_build else ("--build",), "-d") ready(); run("make", "test", "BASE_URL=" + BASE, "CA_FILE=" + CA); run("make", "test-security", "BASE_URL=" + BASE, "CA_FILE=" + CA) if a.full: run("make", "test-persistence", "ACTION_SCRIPT=scripts/restart.sh", "BASE_URL=" + BASE, "CA_FILE=" + CA); run("make", "test-failover", "ACTION_SCRIPT=scripts/stop-one.sh", "BASE_URL=" + BASE, "CA_FILE=" + CA) if a.load: run("python3", "tests/load.py", "--base-url", BASE, "--ca-file", CA, "--duration", "30", "--concurrency", "4") print("Готово. Вручную дополнительно показываются mTLS policy, OpenBao allow/deny и rotation evidence.") if __name__ == "__main__": main()