Agent: Add control channel server property

This commit is contained in:
Ilija Lazoroski 2021-11-23 11:13:14 +01:00
parent 65bc0efc5a
commit 56f07e0188
2 changed files with 15 additions and 7 deletions

View File

@ -14,14 +14,15 @@ logger = logging.getLogger(__name__)
class ControlChannel(IControlChannel):
control_channel_server = WormConfiguration.current_server
def should_agent_stop(self) -> bool:
server = WormConfiguration.current_server
if not server:
if not self.control_channel_server:
return
try:
response = requests.get( # noqa: DUO123
f"{server}/api/monkey_control/{GUID}",
f"{self.control_channel_server}/api/monkey_control/{GUID}",
verify=False,
timeout=SHORT_REQUEST_TIMEOUT,
)
@ -32,16 +33,16 @@ class ControlChannel(IControlChannel):
logger.error(f"An error occurred while trying to connect to server. {e}")
def get_config(self) -> dict:
return ControlClient.load_control_config()
ControlClient.load_control_config()
return WormConfiguration.as_dict()
def get_credentials_for_propagation(self) -> dict:
server = WormConfiguration.current_server
if not server:
if not self.control_channel_server:
return
try:
response = requests.get( # noqa: DUO123
f"{server}/api/propagationCredentials",
f"{self.control_channel_server}/api/propagationCredentials",
verify=False,
timeout=SHORT_REQUEST_TIMEOUT,
)

View File

@ -2,6 +2,13 @@ import abc
class IControlChannel(metaclass=abc.ABCMeta):
@property
@abc.abstractmethod
def control_channel_server(self):
"""
:return: Worm configuration server
"""
@abc.abstractmethod
def should_agent_stop(self) -> bool:
"""