From 0ca13eb93dcee570a1d6e753a82fd212319d364f Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Mon, 12 Sep 2022 15:59:58 +0200 Subject: [PATCH] Island: Add subscribe_to_topics on server setup --- monkey/monkey_island/cc/__init__.py | 1 + monkey/monkey_island/cc/server_setup.py | 4 +++- monkey/monkey_island/cc/subscribe_to_topics.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 monkey/monkey_island/cc/subscribe_to_topics.py diff --git a/monkey/monkey_island/cc/__init__.py b/monkey/monkey_island/cc/__init__.py index 1a7e6c0ea..89172f65f 100644 --- a/monkey/monkey_island/cc/__init__.py +++ b/monkey/monkey_island/cc/__init__.py @@ -1 +1,2 @@ from .version import Version +from .subscribe_to_topics import subscribe_to_topics diff --git a/monkey/monkey_island/cc/server_setup.py b/monkey/monkey_island/cc/server_setup.py index e98c4f652..b297cae42 100644 --- a/monkey/monkey_island/cc/server_setup.py +++ b/monkey/monkey_island/cc/server_setup.py @@ -10,7 +10,7 @@ import gevent.hub import requests from gevent.pywsgi import WSGIServer -from monkey_island.cc import Version +from monkey_island.cc import Version, subscribe_to_topics from monkey_island.cc.deployment import Deployment from monkey_island.cc.server_utils.consts import ISLAND_PORT from monkey_island.cc.server_utils.island_logger import get_log_file_path @@ -62,6 +62,8 @@ def run_monkey_island(): _initialize_mongodb_connection(config_options.start_mongodb, config_options.data_dir) _start_island_server(ip_addresses, island_args.setup_only, config_options, container) + subscribe_to_topics(container) + def _extract_config(island_args: IslandCmdArgs) -> IslandConfigOptions: try: diff --git a/monkey/monkey_island/cc/subscribe_to_topics.py b/monkey/monkey_island/cc/subscribe_to_topics.py new file mode 100644 index 000000000..ef5154084 --- /dev/null +++ b/monkey/monkey_island/cc/subscribe_to_topics.py @@ -0,0 +1,11 @@ +from common import DIContainer +from monkey_island.cc.event_queue import IslandEventTopic, PyPubSubIslandEventQueue +from monkey_island.cc.services.reset_agent_configuration import reset_agent_configuration + + +def subscribe_to_topics(container: DIContainer): + event_queue = container.resolve(PyPubSubIslandEventQueue) + + event_queue.subscribe( + IslandEventTopic.RESET_AGENT_CONFIGURATION, container.resolve(reset_agent_configuration) + )