Lab7: HTTPS, mTLS, OpenBao, трек 2 PKI на оценку 5
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Ждать GET /health/ready через HTTPS балансировщик. Без токенов в выводе."""
|
||||
import os
|
||||
import ssl
|
||||
import sys
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
BASE = os.environ.get("BASE_URL", "https://127.0.0.1:8443").rstrip("/")
|
||||
URL = BASE + "/health/ready"
|
||||
CA = os.environ.get("CA_FILE") or str(ROOT / "certs" / "ca.crt")
|
||||
|
||||
|
||||
def main():
|
||||
context = ssl.create_default_context(cafile=CA)
|
||||
deadline = time.monotonic() + 120
|
||||
last = "not-started"
|
||||
while time.monotonic() < deadline:
|
||||
try:
|
||||
req = urllib.request.Request(URL)
|
||||
response = urllib.request.urlopen(req, timeout=2, context=context)
|
||||
if response.status == 200 and response.headers.get("X-Instance-Id"):
|
||||
print("ready")
|
||||
return 0
|
||||
last = str(response.status)
|
||||
except (urllib.error.URLError, TimeoutError, OSError) as exc:
|
||||
last = type(exc).__name__
|
||||
time.sleep(1)
|
||||
print("not ready: " + last, file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user