Agent: Fix functions defined in HTTPIslandAPIClient and use the handle_island_errors() decorator on them

This commit is contained in:
Shreya Malviya 2022-09-19 18:38:37 +05:30 committed by Mike Salvatore
parent fa9225370e
commit 8ab17a96e3
1 changed files with 32 additions and 15 deletions

View File

@ -24,8 +24,24 @@ def handle_island_errors(fn):
return decorated return decorated
class HTTPIslandAPIClient(IIslandAPIClient):
"""
A client for the Island's HTTP API
"""
@handle_island_errors
def __init__(self, island_server: str):
requests.get( # noqa: DUO123
f"https://{island_server}/api?action=is-up",
verify=False,
timeout=MEDIUM_REQUEST_TIMEOUT,
)
self._island_server = island_server
# TODO: set server address as object property when init is called in find_server and pass # TODO: set server address as object property when init is called in find_server and pass
# object around? won't need to pass island server and create object in every function # object around? won't need to pass island server and create object in every function
@handle_island_errors
def send_log(self, data: str): def send_log(self, data: str):
requests.post( # noqa: DUO123 requests.post( # noqa: DUO123
"https://%s/api/log" % (self._island_server,), "https://%s/api/log" % (self._island_server,),
@ -34,6 +50,7 @@ def handle_island_errors(fn):
timeout=MEDIUM_REQUEST_TIMEOUT, timeout=MEDIUM_REQUEST_TIMEOUT,
) )
@handle_island_errors
def get_pba_file(self, filename: str): def get_pba_file(self, filename: str):
return requests.get( # noqa: DUO123 return requests.get( # noqa: DUO123
"https://%s/api/pba/download/%s" % (self.server_address, filename), "https://%s/api/pba/download/%s" % (self.server_address, filename),