From 2fb3e92f9fc97445e08e6ee20c62e5ad68186137 Mon Sep 17 00:00:00 2001 From: TOUFIKI Zakarya Date: Tue, 3 Dec 2024 14:38:43 +0100 Subject: [PATCH] Add list to validate response --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- sekoia_automation/action.py | 10 ++++++++++ tests/test_action.py | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18f500a..604237f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## 1.18.2 - 2024-12-03 + +### Add + +- Add the support to list type for action response + ## 1.18.1 - 2024-12-03 ### Add diff --git a/pyproject.toml b/pyproject.toml index 0cc2591..665a12d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "sekoia-automation-sdk" -version = "1.18.1" +version = "1.18.2" description = "SDK to create Sekoia.io playbook modules" license = "MIT" readme = "README.md" diff --git a/sekoia_automation/action.py b/sekoia_automation/action.py index 5fe1114..0073095 100644 --- a/sekoia_automation/action.py +++ b/sekoia_automation/action.py @@ -212,6 +212,16 @@ def validate_results(self): except Exception: sentry_sdk.capture_exception() + # Add a check for list + if isinstance(self._results, list): + for result in self._results: + if isinstance(result, dict): + try: + orjson.dumps(result) + except Exception: + sentry_sdk.capture_exception() + return + # If we reached this point, the results are invalid self._error = f"Results are invalid: '{self._results}'" self._results = None diff --git a/tests/test_action.py b/tests/test_action.py index 4ec436c..bed48a8 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -171,6 +171,24 @@ def test_validate_results_none(): assert action.error_message is None +def test_validate_list_results(mock_volume): + class ListAction(Action): + def run(self, arguments): + return [{"key1": "value1"}, {"key2": "value2"}] + + action = ListAction() + + with requests_mock.Mocker() as rmock: + rmock.patch(FAKE_URL) + + action.execute() + + assert rmock.last_request.json()["results"] == [ + {"key1": "value1"}, + {"key2": "value2"}, + ] + + def test_action_results_invalid(mock_volume): class TestAction(Action): def run(self, arguments):