import json import ssl import urllib.request from urllib.error import HTTPError from tls_matrix import context def request(role,path,body=None,token=None): headers={'Content-Type':'application/json'} if token:headers['X-Vault-Token']=token req=urllib.request.Request('https://openbao:8200/v1/'+path,headers=headers, data=json.dumps(body).encode() if body is not None else None) try: with urllib.request.urlopen(req,context=context(role),timeout=5) as r: raw=r.read();return r.status,json.loads(raw) if raw else {} except HTTPError as e:return e.code,{} results=[] for role in ('api1','api2','worker','dispatcher','reconciler'): code,data=request(role,'auth/cert/login',{'name':role}) assert code==200,(role,code) auth=data['auth'];token=auth['client_token'] assert 0