Skip to content

Commit 16e02a5

Browse files
node-intasller api adjusted with the zeuz request abstraction
1 parent 8eebe34 commit 16e02a5

3 files changed

Lines changed: 56 additions & 65 deletions

File tree

Framework/deploy_handler/long_poll_handler.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ def respond_to_key_request(self, request_id: str, private_key_pem: str) -> None:
238238
"donor_node_id": node_id,
239239
"private_key": private_key_pem
240240
},
241-
verify=False
242241
)
243242

244243
if response.ok:
@@ -266,7 +265,7 @@ async def run(self, host: str) -> None:
266265

267266
try:
268267
reconnect = True
269-
resp = RequestFormatter.request("get", host, verify=False, timeout=70)
268+
resp = RequestFormatter.request("get", host, timeout=70)
270269
if resp is None:
271270
break
272271

@@ -290,9 +289,9 @@ async def run(self, host: str) -> None:
290289

291290
if not resp.ok:
292291
print(
293-
"[deploy] facing difficulty communicating with the server, status code:",
292+
"[deploy] Request Error, status code:",
294293
resp.status_code,
295-
" | reconnecting",
294+
"| reconnecting",
296295
)
297296

298297
# Encountered a server error, retry.

Framework/install_handler/long_poll_handler.py

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -324,62 +324,49 @@ async def run(self) -> None:
324324
return
325325
if debug:
326326
print(f"[installer] Started running")
327-
async with httpx.AsyncClient(
328-
timeout=httpx.Timeout(70.0), verify=False
329-
) as client:
330-
self.client = client
331-
while not self.cancel_:
332-
if STATE.reconnect_with_credentials is not None:
333-
if debug:
334-
print("[installer] Reconnection requested, stopping...")
335-
break
327+
328+
while not self.cancel_:
329+
if STATE.reconnect_with_credentials is not None:
330+
if debug:
331+
print("[installer] Reconnection requested, stopping...")
332+
break
336333

337-
self.running = True
338-
try:
339-
if debug:
340-
print("[installer] Active")
341-
api_key = ConfigModule.get_config_value("Authentication", "api-key")
342-
url = RequestFormatter.form_uri(
343-
f"d/nodes/install/node/listen?node_id={read_node_id()}"
344-
)
334+
self.running = True
335+
try:
336+
if debug:
337+
print("[installer] Active")
338+
host = RequestFormatter.form_uri(
339+
f"d/nodes/install/node/listen?node_id={read_node_id()}"
340+
)
345341

346-
resp = await client.get(url, headers={"X-API-KEY": api_key})
347-
if resp.status_code == httpx.codes.NO_CONTENT:
348-
continue
342+
resp = resp = RequestFormatter.request("get", host, timeout=70)
349343

350-
if not resp.is_success:
351-
if debug:
352-
print(
353-
"[installer] facing difficulty communicating with the server, status code:",
354-
resp.status_code,
355-
" | reconnecting",
356-
)
357-
print(Fore.YELLOW + str(resp.content))
344+
if not resp.ok:
345+
if debug:
346+
print(
347+
"[installer] Request Error, status code:",
348+
resp.status_code,
349+
"| retrying after 15 sec",
350+
)
351+
print(Fore.YELLOW + str(resp.content))
358352

359-
await asyncio.sleep(random.randint(1, 3))
360-
continue
353+
await asyncio.sleep(15)
354+
continue
361355

362-
try:
363-
data = resp.json()
364-
if data:
365-
validated_data = Response(**data)
366-
await self.on_message(validated_data)
367-
except Exception as e:
368-
print(f"[installer] Error parsing response: {e}")
369-
continue
356+
try:
357+
data = resp.json()
358+
if data:
359+
validated_data = Response(**data)
360+
await self.on_message(validated_data)
361+
except Exception as e:
362+
print(f"[installer] Type Error in parsing response: {e}")
363+
continue
370364

371-
except httpx.ReadTimeout:
372-
pass
373-
except httpx.ConnectError:
374-
if debug:
375-
print("[installer] Connection error, retrying...")
376-
await asyncio.sleep(random.randint(3, 5))
377-
except Exception:
378-
if debug:
379-
traceback.print_exc()
380-
if debug:
381-
print("[installer] RETRYING...")
382-
await asyncio.sleep(random.randint(1, 3))
365+
except Exception:
366+
if debug:
367+
traceback.print_exc()
368+
print("[installer] RETRYING...")
369+
await asyncio.sleep(random.randint(1, 3))
383370

384371
self.running = False
385372
print("[installer] Stopped running")

Framework/install_handler/utils.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import datetime
2-
import httpx
2+
import asyncio
33
import platform
44
from Framework.Utilities import RequestFormatter, ConfigModule, CommonUtil
55

@@ -42,9 +42,7 @@ def generate_services_list(services):
4242
async def send_response(data=None) -> None:
4343
try:
4444
from Framework.install_handler.route import services
45-
46-
api_key = ConfigModule.get_config_value("Authentication", "api-key")
47-
url = RequestFormatter.form_uri("d/nodes/install/server/push")
45+
host = RequestFormatter.form_uri("d/nodes/install/server/push")
4846
data['last_updated'] = datetime.datetime.now(datetime.timezone.utc).timestamp()
4947
data['version'] = version
5048
data['node_id'] = read_node_id()
@@ -60,13 +58,20 @@ async def send_response(data=None) -> None:
6058
if debug:
6159
print(f"[installer] Sending response to server: {data}")
6260

63-
async with httpx.AsyncClient(timeout=30.0, verify=False) as client:
64-
resp = await client.post(url, json=data, headers={"X-API-KEY": api_key})
65-
if debug:
66-
print(f"[installer] Response status: {resp.status_code}")
67-
print(f"[installer] Response content: {resp.content}")
68-
if not resp.is_success:
61+
for _ in range(3):
62+
try:
63+
resp = RequestFormatter.request("post", host, json=data, timeout=70)
6964
if debug:
70-
print(f"[installer] Failed to send response: {resp.status_code}")
65+
print(f"[installer] Response status: {resp.status_code}")
66+
print(f"[installer] Response content: {resp.content}")
67+
if not resp.ok:
68+
if debug:
69+
print(f"[installer] Failed to send response: {resp.status_code}")
70+
await asyncio.sleep(3,5)
71+
else:
72+
break
73+
except Exception as e:
74+
if debug: print(e)
75+
await asyncio.sleep(3,5)
7176
except Exception as e:
7277
print(f"[installer] Error sending response: {e}")

0 commit comments

Comments
 (0)