From f20f11265bb1b733c69062f4dcc679c36e555d2e Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 21 Sep 2022 16:03:03 +0530 Subject: [PATCH] Island: Add set_island_mode Island event handler --- .../cc/island_event_handlers/__init__.py | 1 + .../island_event_handlers/set_island_mode.py | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 monkey/monkey_island/cc/island_event_handlers/set_island_mode.py diff --git a/monkey/monkey_island/cc/island_event_handlers/__init__.py b/monkey/monkey_island/cc/island_event_handlers/__init__.py index 0c977976e..92e385715 100644 --- a/monkey/monkey_island/cc/island_event_handlers/__init__.py +++ b/monkey/monkey_island/cc/island_event_handlers/__init__.py @@ -1,2 +1,3 @@ from .reset_agent_configuration import reset_agent_configuration from .reset_machine_repository import reset_machine_repository +from .set_island_mode import set_island_mode diff --git a/monkey/monkey_island/cc/island_event_handlers/set_island_mode.py b/monkey/monkey_island/cc/island_event_handlers/set_island_mode.py new file mode 100644 index 000000000..9e13ccef2 --- /dev/null +++ b/monkey/monkey_island/cc/island_event_handlers/set_island_mode.py @@ -0,0 +1,32 @@ +from typing import Any + +from common.agent_configuration import AgentConfiguration +from monkey_island.cc.models import IslandMode +from monkey_island.cc.repository import IAgentConfigurationRepository + + +class set_island_mode: + """ + Callable class that sets the Island's mode + """ + + def __init__( + self, + agent_configuration_repository: IAgentConfigurationRepository, + default_agent_configuration: AgentConfiguration, + default_ransomware_agent_configuration: AgentConfiguration, + ): + self._agent_configuration_repository = agent_configuration_repository + self._default_agent_configuration = default_agent_configuration + self._default_ransomware_agent_configuration = default_ransomware_agent_configuration + + def __call__(self, event: Any = None): + mode = event + if mode == IslandMode.RANSOMWARE: + self._agent_configuration_repository.store_configuration( + self._default_ransomware_agent_configuration + ) + else: + self._agent_configuration_repository.store_configuration( + self._default_agent_configuration + )