Island: Add set_island_mode Island event handler

This commit is contained in:
Shreya Malviya 2022-09-21 16:03:03 +05:30
parent 67e280fd7a
commit f20f11265b
2 changed files with 33 additions and 0 deletions

View File

@ -1,2 +1,3 @@
from .reset_agent_configuration import reset_agent_configuration from .reset_agent_configuration import reset_agent_configuration
from .reset_machine_repository import reset_machine_repository from .reset_machine_repository import reset_machine_repository
from .set_island_mode import set_island_mode

View File

@ -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
)