Island: Use container.resolve(ScanEventHandler)

This commit is contained in:
Mike Salvatore 2022-09-30 12:28:22 -04:00
parent 0c786dfd94
commit 07fa283ce1
1 changed files with 3 additions and 12 deletions

View File

@ -6,13 +6,7 @@ from monkey_island.cc.agent_event_handlers import (
save_event_to_event_repository, save_event_to_event_repository,
save_stolen_credentials_to_repository, save_stolen_credentials_to_repository,
) )
from monkey_island.cc.repository import ( from monkey_island.cc.repository import IAgentEventRepository, ICredentialsRepository
IAgentEventRepository,
IAgentRepository,
ICredentialsRepository,
IMachineRepository,
INodeRepository,
)
def setup_agent_event_handlers(container: DIContainer): def setup_agent_event_handlers(container: DIContainer):
@ -23,6 +17,7 @@ def setup_agent_event_handlers(container: DIContainer):
def _subscribe_and_store_to_event_repository(container: DIContainer): def _subscribe_and_store_to_event_repository(container: DIContainer):
agent_event_queue = container.resolve(IAgentEventQueue) agent_event_queue = container.resolve(IAgentEventQueue)
# TODO: Can't we just `container.resolve(save_event_to_event_repository)`?
save_event_subscriber = save_event_to_event_repository(container.resolve(IAgentEventRepository)) save_event_subscriber = save_event_to_event_repository(container.resolve(IAgentEventRepository))
agent_event_queue.subscribe_all_events(save_event_subscriber) agent_event_queue.subscribe_all_events(save_event_subscriber)
@ -34,11 +29,7 @@ def _subscribe_and_store_to_event_repository(container: DIContainer):
def _subscribe_scan_events(container: DIContainer): def _subscribe_scan_events(container: DIContainer):
agent_event_queue = container.resolve(IAgentEventQueue) agent_event_queue = container.resolve(IAgentEventQueue)
agent_repository = container.resolve(IAgentRepository) scan_event_handler = container.resolve(ScanEventHandler)
machine_repository = container.resolve(IMachineRepository)
node_repository = container.resolve(INodeRepository)
scan_event_handler = ScanEventHandler(agent_repository, machine_repository, node_repository)
agent_event_queue.subscribe_type(PingScanEvent, scan_event_handler.handle_ping_scan_event) agent_event_queue.subscribe_type(PingScanEvent, scan_event_handler.handle_ping_scan_event)
agent_event_queue.subscribe_type(TCPScanEvent, scan_event_handler.handle_tcp_scan_event) agent_event_queue.subscribe_type(TCPScanEvent, scan_event_handler.handle_tcp_scan_event)