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,19 +24,36 @@ def handle_island_errors(fn):
return decorated return decorated
# 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
def send_log(self, data: str):
requests.post( # noqa: DUO123
"https://%s/api/log" % (self._island_server,),
json=data,
verify=False,
timeout=MEDIUM_REQUEST_TIMEOUT,
)
def get_pba_file(self, filename: str): class HTTPIslandAPIClient(IIslandAPIClient):
return requests.get( # noqa: DUO123 """
"https://%s/api/pba/download/%s" % (self.server_address, filename), A client for the Island's HTTP API
verify=False, """
timeout=LONG_REQUEST_TIMEOUT,
) @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
# object around? won't need to pass island server and create object in every function
@handle_island_errors
def send_log(self, data: str):
requests.post( # noqa: DUO123
"https://%s/api/log" % (self._island_server,),
json=data,
verify=False,
timeout=MEDIUM_REQUEST_TIMEOUT,
)
@handle_island_errors
def get_pba_file(self, filename: str):
return requests.get( # noqa: DUO123
"https://%s/api/pba/download/%s" % (self.server_address, filename),
verify=False,
timeout=LONG_REQUEST_TIMEOUT,
)