"""Read the deployed coordinator status using its existing service signature.""" from pathlib import Path import hashlib import hmac import json import time import urllib.request import uuid def status(): config = Path('E:/Codex/xtrh/runtime/coordinator/config/cluster.local.properties') key = next(line.split('=',1)[1].strip() for line in config.read_text(encoding='utf-8-sig').splitlines() if line.startswith('fusion.token=')).encode() path = '/node/input/status' nonce, stamp = str(uuid.uuid4()), str(time.time_ns()//1000000) sign = lambda value: hmac.new(key, value.encode(), 'sha256').hexdigest() signature = sign('\n'.join(['request','GET',path,stamp,nonce,hashlib.sha256(b'').hexdigest()])) request = urllib.request.Request('http://127.0.0.1:18100'+path, headers={'X-Xtrh-Time':stamp,'X-Xtrh-Nonce':nonce,'X-Xtrh-Signature':signature}) opener = urllib.request.build_opener(urllib.request.ProxyHandler({})) with opener.open(request,timeout=5) as response: raw = response.read() expected = sign('\n'.join(['response',nonce,str(response.status),hashlib.sha256(raw).hexdigest()])) assert hmac.compare_digest(expected,response.headers.get('X-Xtrh-Response-Signature','')) return json.loads(raw) if __name__ == '__main__': print(json.dumps(status(),ensure_ascii=True,indent=2))