forked from p15670423/monkey
Agent: Call get "/api/monkey" endpoint from ControlChannel.get_config()
This commit is contained in:
parent
30afe3cc85
commit
02c725d1f8
|
@ -19,37 +19,51 @@ class ControlChannel(IControlChannel):
|
||||||
self._control_channel_server = server
|
self._control_channel_server = server
|
||||||
|
|
||||||
def should_agent_stop(self) -> bool:
|
def should_agent_stop(self) -> bool:
|
||||||
if not self._control_channel_server:
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get( # noqa: DUO123
|
response = requests.get( # noqa: DUO123
|
||||||
f"{self._control_channel_server}/api/monkey_control/{self._agent_id}",
|
f"{self._control_channel_server}/api/monkey_control/{self._agent_id}",
|
||||||
verify=False,
|
verify=False,
|
||||||
|
proxies=ControlClient.proxies,
|
||||||
timeout=SHORT_REQUEST_TIMEOUT,
|
timeout=SHORT_REQUEST_TIMEOUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = json.loads(response.content.decode())
|
response = json.loads(response.content.decode())
|
||||||
return response["stop_agent"]
|
return response["stop_agent"]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
# TODO: Evaluate how this exception is handled; don't just log and ignore it.
|
||||||
logger.error(f"An error occurred while trying to connect to server. {e}")
|
logger.error(f"An error occurred while trying to connect to server. {e}")
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def get_config(self) -> dict:
|
def get_config(self) -> dict:
|
||||||
ControlClient.load_control_config()
|
try:
|
||||||
return WormConfiguration.as_dict()
|
response = requests.get( # noqa: DUO123
|
||||||
|
"https://%s/api/monkey/%s" % (WormConfiguration.current_server, self._agent_id),
|
||||||
|
verify=False,
|
||||||
|
proxies=ControlClient.proxies,
|
||||||
|
timeout=SHORT_REQUEST_TIMEOUT,
|
||||||
|
)
|
||||||
|
|
||||||
|
return json.loads(response.content.decode())
|
||||||
|
except Exception as exc:
|
||||||
|
# TODO: Evaluate how this exception is handled; don't just log and ignore it.
|
||||||
|
logger.warning(
|
||||||
|
"Error connecting to control server %s: %s", WormConfiguration.current_server, exc
|
||||||
|
)
|
||||||
|
|
||||||
|
return {}
|
||||||
|
|
||||||
def get_credentials_for_propagation(self) -> dict:
|
def get_credentials_for_propagation(self) -> dict:
|
||||||
if not self._control_channel_server:
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get( # noqa: DUO123
|
response = requests.get( # noqa: DUO123
|
||||||
f"{self._control_channel_server}/api/propagationCredentials",
|
f"{self._control_channel_server}/api/propagationCredentials",
|
||||||
verify=False,
|
verify=False,
|
||||||
|
proxies=ControlClient.proxies,
|
||||||
timeout=SHORT_REQUEST_TIMEOUT,
|
timeout=SHORT_REQUEST_TIMEOUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = json.loads(response.content.decode())["propagation_credentials"]
|
response = json.loads(response.content.decode())["propagation_credentials"]
|
||||||
return response
|
return response
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
# TODO: Evaluate how this exception is handled; don't just log and ignore it.
|
||||||
logger.error(f"An error occurred while trying to connect to server. {e}")
|
logger.error(f"An error occurred while trying to connect to server. {e}")
|
||||||
|
|
Loading…
Reference in New Issue