Files
mtusi2026lab7/scripts/wait_ready.py
T
Khakimov Dmitrij 2a7418fc45
Skeleton contracts / contracts (pull_request) Blocked by required conditions
lab 7 done
2026-11-29 21:59:16 +03:00

28 lines
938 B
Python

#!/usr/bin/env python3
"""Wait for HTTPS readiness with the lab CA."""
import argparse
import ssl
import time
import urllib.error
import urllib.request
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--base-url", default="https://localhost:8443")
parser.add_argument("--ca-file", default=".runtime/trust/ca.crt")
args = parser.parse_args()
if not args.base_url.startswith("https://"):
parser.error("HTTPS is required")
context = ssl.create_default_context(cafile=args.ca_file)
deadline = time.monotonic() + 120
while time.monotonic() < deadline:
try:
with urllib.request.urlopen(args.base_url + "/health/ready", timeout=3, context=context) as response:
if response.status == 200:
print("API is ready")
break
except (OSError, urllib.error.URLError):
time.sleep(1)
else:
raise SystemExit("API did not become ready within 120 seconds")