Merge remote-tracking branch 'origin/dev' into feature/2257-router-routes-cannot-be-represented-in-config-file
This commit is contained in:
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Fixed a bug where the red agent acted to early
|
- Fixed a bug where the red agent acted to early
|
||||||
- Fixed the order of service health state
|
- Fixed the order of service health state
|
||||||
- Fixed an issue where starting a node didn't start the services on it
|
- Fixed an issue where starting a node didn't start the services on it
|
||||||
|
- Added support for SQL INSERT command.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ Key capabilities
|
|||||||
- Creates a database file in the ``Node`` 's ``FileSystem`` upon creation.
|
- Creates a database file in the ``Node`` 's ``FileSystem`` upon creation.
|
||||||
- Handles connecting clients by maintaining a dictionary of connections mapped to session IDs.
|
- Handles connecting clients by maintaining a dictionary of connections mapped to session IDs.
|
||||||
- Authenticates connections using a configurable password.
|
- Authenticates connections using a configurable password.
|
||||||
- Simulates ``SELECT`` and ``DELETE`` SQL queries.
|
- Simulates ``SELECT``, ``DELETE`` and ``INSERT`` SQL queries.
|
||||||
- Returns query results and status codes back to clients.
|
- Returns query results and status codes back to clients.
|
||||||
- Leverages the Service base class for install/uninstall, status tracking, etc.
|
- Leverages the Service base class for install/uninstall, status tracking, etc.
|
||||||
|
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ class DatabaseService(Service):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def _process_sql(
|
def _process_sql(
|
||||||
self, query: Literal["SELECT", "DELETE"], query_id: str, connection_id: Optional[str] = None
|
self, query: Literal["SELECT", "DELETE", "INSERT"], query_id: str, connection_id: Optional[str] = None
|
||||||
) -> Dict[str, Union[int, List[Any]]]:
|
) -> Dict[str, Union[int, List[Any]]]:
|
||||||
"""
|
"""
|
||||||
Executes the given SQL query and returns the result.
|
Executes the given SQL query and returns the result.
|
||||||
@@ -197,6 +197,7 @@ class DatabaseService(Service):
|
|||||||
Possible queries:
|
Possible queries:
|
||||||
- SELECT : returns the data
|
- SELECT : returns the data
|
||||||
- DELETE : deletes the data
|
- DELETE : deletes the data
|
||||||
|
- INSERT : inserts the data
|
||||||
|
|
||||||
:param query: The SQL query to be executed.
|
:param query: The SQL query to be executed.
|
||||||
:return: Dictionary containing status code and data fetched.
|
:return: Dictionary containing status code and data fetched.
|
||||||
@@ -220,9 +221,27 @@ class DatabaseService(Service):
|
|||||||
return {"status_code": 404, "data": False}
|
return {"status_code": 404, "data": False}
|
||||||
elif query == "DELETE":
|
elif query == "DELETE":
|
||||||
self.db_file.health_status = FileSystemItemHealthStatus.COMPROMISED
|
self.db_file.health_status = FileSystemItemHealthStatus.COMPROMISED
|
||||||
return {"status_code": 200, "type": "sql", "data": False, "uuid": query_id, "connection_id": connection_id}
|
return {
|
||||||
|
"status_code": 200,
|
||||||
|
"type": "sql",
|
||||||
|
"data": False,
|
||||||
|
"uuid": query_id,
|
||||||
|
"connection_id": connection_id,
|
||||||
|
}
|
||||||
|
elif query == "INSERT":
|
||||||
|
if self.health_state_actual == SoftwareHealthState.GOOD:
|
||||||
|
return {
|
||||||
|
"status_code": 200,
|
||||||
|
"type": "sql",
|
||||||
|
"data": False,
|
||||||
|
"uuid": query_id,
|
||||||
|
"connection_id": connection_id,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
return {"status_code": 404, "data": False}
|
||||||
else:
|
else:
|
||||||
# Invalid query
|
# Invalid query
|
||||||
|
self.sys_log.info(f"{self.name}: Invalid {query}")
|
||||||
return {"status_code": 500, "data": False}
|
return {"status_code": 500, "data": False}
|
||||||
|
|
||||||
def describe_state(self) -> Dict:
|
def describe_state(self) -> Dict:
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ def test_database_client_query(uc2_network):
|
|||||||
db_client.connect()
|
db_client.connect()
|
||||||
|
|
||||||
assert db_client.query("SELECT")
|
assert db_client.query("SELECT")
|
||||||
|
assert db_client.query("INSERT")
|
||||||
|
|
||||||
|
|
||||||
def test_create_database_backup(uc2_network):
|
def test_create_database_backup(uc2_network):
|
||||||
@@ -150,7 +151,7 @@ def test_database_client_cannot_query_offline_database_server(uc2_network):
|
|||||||
assert len(db_client.connections)
|
assert len(db_client.connections)
|
||||||
|
|
||||||
assert db_client.query("SELECT") is True
|
assert db_client.query("SELECT") is True
|
||||||
|
assert db_client.query("INSERT") is True
|
||||||
db_server.power_off()
|
db_server.power_off()
|
||||||
|
|
||||||
for i in range(db_server.shut_down_duration + 1):
|
for i in range(db_server.shut_down_duration + 1):
|
||||||
@@ -160,3 +161,4 @@ def test_database_client_cannot_query_offline_database_server(uc2_network):
|
|||||||
assert db_service.operating_state is ServiceOperatingState.STOPPED
|
assert db_service.operating_state is ServiceOperatingState.STOPPED
|
||||||
|
|
||||||
assert db_client.query("SELECT") is False
|
assert db_client.query("SELECT") is False
|
||||||
|
assert db_client.query("INSERT") is False
|
||||||
|
|||||||
Reference in New Issue
Block a user