From ceac89e77849e571c0c0ef604d9285990feac692 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 8 Sep 2023 10:15:26 +0100 Subject: [PATCH] #1816 - DatabaseService now uses the send function when responding. --- .../simulator/system/core/packet_capture.py | 2 +- .../simulator/system/services/database.py | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index b1e35a77..2e5ed008 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -52,7 +52,7 @@ class PacketCapture: self.logger.addFilter(_JSONFilter()) - def read(self) -> List[Dict[Any]]: + def read(self) -> List[Dict[str, Any]]: """ Read packet capture logs and return them as a list of dictionaries. diff --git a/src/primaite/simulator/system/services/database.py b/src/primaite/simulator/system/services/database.py index c02b2872..dc148031 100644 --- a/src/primaite/simulator/system/services/database.py +++ b/src/primaite/simulator/system/services/database.py @@ -95,10 +95,22 @@ class DatabaseService(Service): :param payload: The SQL query to be executed. :param session_id: The session identifier. - :return: The status code of the SQL execution. + :return: True if the Status Code is 200, otherwise False. """ result = self._process_sql(payload) - software_manager: SoftwareManager = self.software_manager - software_manager.send_payload_to_session_manager(payload=result, session_id=session_id) + self.send(payload=result, session_id=session_id) - return result["status_code"] == 200 + return payload["status_code"] == 200 + + def send(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Send a SQL response back down to the SessionManager. + + :param payload: The SQL query results. + :param session_id: The session identifier. + :return: True if the Status Code is 200, otherwise False. + """ + software_manager: SoftwareManager = self.software_manager + software_manager.send_payload_to_session_manager(payload=payload, session_id=session_id) + + return payload["status_code"] == 200