From 1f96ab5ea97eca3431f51684fe99848558006850 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 21 Sep 2022 16:26:04 +0530 Subject: [PATCH] Island: Extract event topic to a variable in all Island event handler subscribe functions --- .../cc/setup/island_event_handlers.py | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/monkey/monkey_island/cc/setup/island_event_handlers.py b/monkey/monkey_island/cc/setup/island_event_handlers.py index 65d9cff51..46429f292 100644 --- a/monkey/monkey_island/cc/setup/island_event_handlers.py +++ b/monkey/monkey_island/cc/setup/island_event_handlers.py @@ -28,25 +28,23 @@ def setup_island_event_handlers(container: DIContainer): def _subscribe_reset_agent_configuration_events( island_event_queue: IIslandEventQueue, container: DIContainer ): - island_event_queue.subscribe( - IslandEventTopic.RESET_AGENT_CONFIGURATION, container.resolve(reset_agent_configuration) - ) + topic = IslandEventTopic.RESET_AGENT_CONFIGURATION + + island_event_queue.subscribe(topic, container.resolve(reset_agent_configuration)) def _subscribe_clear_simulation_data_events( island_event_queue: IIslandEventQueue, container: DIContainer ): + topic = IslandEventTopic.CLEAR_SIMULATION_DATA + legacy_database_reset = partial(Database.reset_db, reset_config=False) - island_event_queue.subscribe(IslandEventTopic.CLEAR_SIMULATION_DATA, legacy_database_reset) + island_event_queue.subscribe(topic, legacy_database_reset) credentials_repository = container.resolve(ICredentialsRepository) - island_event_queue.subscribe( - IslandEventTopic.CLEAR_SIMULATION_DATA, credentials_repository.remove_stolen_credentials - ) + island_event_queue.subscribe(topic, credentials_repository.remove_stolen_credentials) - island_event_queue.subscribe( - IslandEventTopic.CLEAR_SIMULATION_DATA, container.resolve(reset_machine_repository) - ) + island_event_queue.subscribe(topic, container.resolve(reset_machine_repository)) for i_repository in [ INodeRepository, @@ -54,15 +52,14 @@ def _subscribe_clear_simulation_data_events( IAgentRepository, ]: repository = container.resolve(i_repository) - island_event_queue.subscribe(IslandEventTopic.CLEAR_SIMULATION_DATA, repository.reset) + island_event_queue.subscribe(topic, repository.reset) def _subscribe_set_island_mode_events( island_event_queue: IIslandEventQueue, container: DIContainer ): - island_event_queue.subscribe( - IslandEventTopic.SET_ISLAND_MODE, container.resolve(set_agent_configuration_per_island_mode) - ) - island_event_queue.subscribe( - IslandEventTopic.SET_ISLAND_MODE, container.resolve(set_simulation_mode) - ) + topic = IslandEventTopic.SET_ISLAND_MODE + + island_event_queue.subscribe(topic, container.resolve(set_agent_configuration_per_island_mode)) + + island_event_queue.subscribe(topic, container.resolve(set_simulation_mode))