#!/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")