forked from p15670423/monkey
Agent: Make HTTPIslandAPIClient.send_log() and HTTPIslandAPIClient.get_pba_file() static
This commit is contained in:
parent
8ab17a96e3
commit
d07760fe60
|
@ -77,12 +77,12 @@ class ControlClient:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
telemetry = {"monkey_guid": GUID, "log": json.dumps(log)}
|
telemetry = {"monkey_guid": GUID, "log": json.dumps(log)}
|
||||||
HTTPIslandAPIClient(self.server_address).send_log(json.dumps(telemetry))
|
HTTPIslandAPIClient.send_log(self.server_address, json.dumps(telemetry))
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning(f"Error connecting to control server {self.server_address}: {exc}")
|
logger.warning(f"Error connecting to control server {self.server_address}: {exc}")
|
||||||
|
|
||||||
def get_pba_file(self, filename):
|
def get_pba_file(self, filename):
|
||||||
try:
|
try:
|
||||||
HTTPIslandAPIClient(self.server_address).get_pba_file(filename)
|
HTTPIslandAPIClient.get_pba_file(self.server_address, filename)
|
||||||
except requests.exceptions.RequestException:
|
except requests.exceptions.RequestException:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -37,23 +37,24 @@ class HTTPIslandAPIClient(IIslandAPIClient):
|
||||||
verify=False,
|
verify=False,
|
||||||
timeout=MEDIUM_REQUEST_TIMEOUT,
|
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
|
||||||
|
@staticmethod
|
||||||
@handle_island_errors
|
@handle_island_errors
|
||||||
def send_log(self, data: str):
|
def send_log(server_address: str, data: str):
|
||||||
requests.post( # noqa: DUO123
|
requests.post( # noqa: DUO123
|
||||||
"https://%s/api/log" % (self._island_server,),
|
"https://%s/api/log" % (server_address,),
|
||||||
json=data,
|
json=data,
|
||||||
verify=False,
|
verify=False,
|
||||||
timeout=MEDIUM_REQUEST_TIMEOUT,
|
timeout=MEDIUM_REQUEST_TIMEOUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
@handle_island_errors
|
@handle_island_errors
|
||||||
def get_pba_file(self, filename: str):
|
def get_pba_file(server_address: str, 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" % (server_address, filename),
|
||||||
verify=False,
|
verify=False,
|
||||||
timeout=LONG_REQUEST_TIMEOUT,
|
timeout=LONG_REQUEST_TIMEOUT,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue