import http.client, json, ssl def post(port, token, body, cert=None, pki="pki"): """POST a worker result over TLS; cert= presents pki/.pem as the client certificate.""" ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) ctx.load_verify_locations(f"{pki}/ca.pem") if cert: ctx.load_cert_chain(f"{pki}/{cert}.pem", f"{pki}/{cert}.key") c = http.client.HTTPSConnection("127.0.0.1", port, context=ctx, timeout=10) c.request("POST", "/result", json.dumps(body), {"Authorization": f"Bearer {token}", "Content-Type": "application/json", "Content-Length": str(len(json.dumps(body)))}) r = c.getresponse() return r.status