feat: completed tasks for grade 4
Skeleton contracts / contracts (pull_request) Blocked by required conditions

This commit is contained in:
2026-11-22 14:40:35 +03:00
parent 0b97f77d76
commit e0263ba902
42 changed files with 5257 additions and 523 deletions
+20 -8
View File
@@ -15,20 +15,32 @@ TLS = ROOT / "secrets/tls"
ROLES = ("api", "worker", "publisher", "cleanup")
def bootstrap(port: int, *, unseal_only: bool = False) -> None:
address = f"https://localhost:{port}"
context = ssl.create_default_context(cafile=str(TLS / "ca.crt"))
opener = build_opener(NoRedirect(), HTTPSHandler(context=context))
class Bao:
def __init__(self, port: int, certificate: Path | None = None, key: Path | None = None):
self.address = f"https://localhost:{port}/v1/"
context = ssl.create_default_context(cafile=str(TLS / "ca.crt"))
if certificate:
context.load_cert_chain(certificate, key)
self.opener = build_opener(NoRedirect(), HTTPSHandler(context=context))
def call(path, payload=None, *, token=None, method=None):
def call(self, path, payload=None, *, token=None, method=None):
headers = {"Content-Type": "application/json"}
if token:
headers["X-Vault-Token"] = token
request = Request(address + "/v1/" + path, headers=headers, method=method,
request = Request(self.address + path, headers=headers, method=method,
data=None if payload is None else json.dumps(payload).encode())
with opener.open(request, timeout=3) as response:
with self.opener.open(request, timeout=5) as response:
body = response.read()
return json.loads(body) if body else None
return json.loads(body) if body else None
def operator_token(port: int) -> str:
config = ROOT / f"secrets/bao-operator/operator-{port}.json"
return json.loads(config.read_text())["root_token"]
def bootstrap(port: int, *, unseal_only: bool = False) -> None:
call = Bao(port).call
deadline = time.monotonic() + 30
while True: