Agent: Change configuration to object in control channel

This commit is contained in:
vakarisz 2022-06-21 15:57:57 +03:00 committed by Mike Salvatore
parent e83995d962
commit 6b406ef686
3 changed files with 10 additions and 6 deletions

View File

@ -1,5 +1,7 @@
import abc import abc
from common.configuration import AgentConfiguration
class IControlChannel(metaclass=abc.ABCMeta): class IControlChannel(metaclass=abc.ABCMeta):
@abc.abstractmethod @abc.abstractmethod
@ -11,10 +13,10 @@ class IControlChannel(metaclass=abc.ABCMeta):
""" """
@abc.abstractmethod @abc.abstractmethod
def get_config(self) -> dict: def get_config(self) -> AgentConfiguration:
""" """
:return: A dictionary containing Agent Configuration :return: An AgentConfiguration object
:rtype: dict :rtype: AgentConfiguration
""" """
pass pass

View File

@ -5,6 +5,7 @@ from typing import Mapping
import requests import requests
from common.common_consts.timeouts import SHORT_REQUEST_TIMEOUT from common.common_consts.timeouts import SHORT_REQUEST_TIMEOUT
from common.configuration import AgentConfiguration
from infection_monkey.custom_types import PropagationCredentials from infection_monkey.custom_types import PropagationCredentials
from infection_monkey.i_control_channel import IControlChannel, IslandCommunicationError from infection_monkey.i_control_channel import IControlChannel, IslandCommunicationError
@ -47,7 +48,7 @@ class ControlChannel(IControlChannel):
) as e: ) as e:
raise IslandCommunicationError(e) raise IslandCommunicationError(e)
def get_config(self) -> dict: def get_config(self) -> AgentConfiguration:
try: try:
response = requests.get( # noqa: DUO123 response = requests.get( # noqa: DUO123
f"https://{self._control_channel_server}/api/agent", f"https://{self._control_channel_server}/api/agent",
@ -57,7 +58,7 @@ class ControlChannel(IControlChannel):
) )
response.raise_for_status() response.raise_for_status()
return json.loads(response.content.decode()) return AgentConfiguration.from_dict(json.loads(response.text)["config"])
except ( except (
json.JSONDecodeError, json.JSONDecodeError,
requests.exceptions.ConnectionError, requests.exceptions.ConnectionError,

View File

@ -172,8 +172,9 @@ class InfectionMonkey:
) )
config = control_channel.get_config() config = control_channel.get_config()
keep_tunnel_open_time = control_channel.get_config().keep_tunnel_open_time
self._monkey_inbound_tunnel = self._control_client.create_control_tunnel( self._monkey_inbound_tunnel = self._control_client.create_control_tunnel(
config["config"]["keep_tunnel_open_time"] keep_tunnel_open_time
) )
if self._monkey_inbound_tunnel and should_propagate(config, self._current_depth): if self._monkey_inbound_tunnel and should_propagate(config, self._current_depth):
self._inbound_tunnel_opened = True self._inbound_tunnel_opened = True