feat: completed tasks for grade 4
Skeleton contracts / contracts (pull_request) Blocked by required conditions
Skeleton contracts / contracts (pull_request) Blocked by required conditions
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user