From 4c026241eab48f4c7e2b2c6ec7be13048a7eca9e Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 7 Oct 2022 07:39:47 -0400 Subject: [PATCH] Island: Change method order in ScanEventHandler --- .../agent_event_handlers/scan_event_handler.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/monkey/monkey_island/cc/agent_event_handlers/scan_event_handler.py b/monkey/monkey_island/cc/agent_event_handlers/scan_event_handler.py index f3482b891..3a345e012 100644 --- a/monkey/monkey_island/cc/agent_event_handlers/scan_event_handler.py +++ b/monkey/monkey_island/cc/agent_event_handlers/scan_event_handler.py @@ -63,10 +63,6 @@ class ScanEventHandler: except (RetrievalError, StorageError, UnknownRecordError): logger.exception("Unable to process tcp scan data") - def _get_source_node(self, event: AbstractAgentEvent) -> Node: - machine = self._get_source_machine(event) - return self._node_repository.get_node_by_machine_id(machine.id) - def _get_target_machine(self, event: ScanEvent) -> Machine: try: target_machines = self._machine_repository.get_machines_by_ip(event.target) @@ -79,6 +75,14 @@ class ScanEventHandler: self._machine_repository.upsert_machine(machine) return machine + def _get_source_node(self, event: AbstractAgentEvent) -> Node: + machine = self._get_source_machine(event) + return self._node_repository.get_node_by_machine_id(machine.id) + + def _get_source_machine(self, event: ScanEvent) -> Machine: + agent = self._agent_repository.get_agent_by_id(event.source) + return self._machine_repository.get_machine_by_id(agent.machine_id) + def _update_target_machine_os(self, machine: Machine, event: PingScanEvent): if event.os is not None and machine.operating_system is None: machine.operating_system = event.os @@ -102,7 +106,3 @@ class ScanEventHandler: self._node_repository.upsert_tcp_connections( src_node.machine_id, {target_machine.id: tcp_connections} ) - - def _get_source_machine(self, event: ScanEvent) -> Machine: - agent = self._agent_repository.get_agent_by_id(event.source) - return self._machine_repository.get_machine_by_id(agent.machine_id)