From 8617e36e5b77d294147b3c77f52f64d00c83f93b Mon Sep 17 00:00:00 2001 From: lvoloshyn-sekoia Date: Fri, 29 Nov 2024 13:28:09 +0200 Subject: [PATCH 1/9] Fix checkpoint for timestamps --- CHANGELOG.md | 4 ++++ sekoia_automation/checkpoint.py | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 002493e..25d0a3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix checkpoint for timestamps + ## 1.18.0 - 2024-11-26 ### Changed diff --git a/sekoia_automation/checkpoint.py b/sekoia_automation/checkpoint.py index 7954e3e..e83e4b0 100644 --- a/sekoia_automation/checkpoint.py +++ b/sekoia_automation/checkpoint.py @@ -64,15 +64,15 @@ def datetime_to_file(self, dt: datetime) -> str: return dt.isoformat() @abstractmethod - def from_datetime(self, dt): + def from_datetime(self, dt: datetime) -> Any: raise NotImplementedError @abstractmethod - def to_datetime(self, rp): + def to_datetime(self, rp: Any) -> datetime: raise NotImplementedError @property - def offset(self) -> datetime: + def offset(self) -> Any: if self._most_recent_date_seen is None: if self._lock: self._lock.acquire() @@ -109,13 +109,14 @@ def offset(self) -> datetime: return self.from_datetime(self._most_recent_date_seen) @offset.setter - def offset(self, last_message_date: datetime) -> None: + def offset(self, last_message_date: datetime | int) -> None: if last_message_date is not None: # convert to inner representation - last_message_date = self.to_datetime(last_message_date) + last_message_datetime: datetime = self.to_datetime(last_message_date) + offset_to_compare: datetime = self.to_datetime(self.offset) - if self.offset is None or last_message_date > self.offset: - self._most_recent_date_seen = last_message_date + if self.offset is None or last_message_datetime > offset_to_compare: + self._most_recent_date_seen = last_message_datetime if self._lock: self._lock.acquire() @@ -139,10 +140,10 @@ def offset(self, last_message_date: datetime) -> None: class CheckpointDatetime(CheckpointDatetimeBase): - def from_datetime(self, dt): + def from_datetime(self, dt: datetime) -> datetime: return dt - def to_datetime(self, rp): + def to_datetime(self, rp: datetime) -> datetime: return rp From f1ac77ab22fd9058a0e810550c97eb283d105b7a Mon Sep 17 00:00:00 2001 From: lvoloshyn-sekoia Date: Fri, 29 Nov 2024 13:49:45 +0200 Subject: [PATCH 2/9] Fix checkpoint for timestamps --- sekoia_automation/checkpoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sekoia_automation/checkpoint.py b/sekoia_automation/checkpoint.py index e83e4b0..90db555 100644 --- a/sekoia_automation/checkpoint.py +++ b/sekoia_automation/checkpoint.py @@ -182,7 +182,7 @@ def from_datetime(self, dt) -> int: def to_datetime(self, rp: float | int) -> datetime: # timestamp -> inner representation - return datetime.fromtimestamp(rp / self.multiplier).astimezone(timezone.utc) + return datetime.fromtimestamp(rp / self.multiplier, tz=timezone.utc) class CheckpointCursor(Checkpoint): From ad04fd86a62793a5208d05fd38d221d9fbb1963e Mon Sep 17 00:00:00 2001 From: lvoloshyn-sekoia Date: Fri, 29 Nov 2024 13:58:18 +0200 Subject: [PATCH 3/9] Fix checkpoint for timestamps --- sekoia_automation/checkpoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sekoia_automation/checkpoint.py b/sekoia_automation/checkpoint.py index 90db555..49126ef 100644 --- a/sekoia_automation/checkpoint.py +++ b/sekoia_automation/checkpoint.py @@ -182,7 +182,7 @@ def from_datetime(self, dt) -> int: def to_datetime(self, rp: float | int) -> datetime: # timestamp -> inner representation - return datetime.fromtimestamp(rp / self.multiplier, tz=timezone.utc) + return datetime.fromtimestamp(rp / self.multiplier).replace(tzinfo=timezone.utc) class CheckpointCursor(Checkpoint): From 707f3fc369f057afdeb222e914925b42cbee86a9 Mon Sep 17 00:00:00 2001 From: lvoloshyn-sekoia Date: Fri, 29 Nov 2024 14:01:03 +0200 Subject: [PATCH 4/9] Fix checkpoint for timestamps --- sekoia_automation/checkpoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sekoia_automation/checkpoint.py b/sekoia_automation/checkpoint.py index 49126ef..e83e4b0 100644 --- a/sekoia_automation/checkpoint.py +++ b/sekoia_automation/checkpoint.py @@ -182,7 +182,7 @@ def from_datetime(self, dt) -> int: def to_datetime(self, rp: float | int) -> datetime: # timestamp -> inner representation - return datetime.fromtimestamp(rp / self.multiplier).replace(tzinfo=timezone.utc) + return datetime.fromtimestamp(rp / self.multiplier).astimezone(timezone.utc) class CheckpointCursor(Checkpoint): From 3c1db3144ba467bcf1cd64c7cc488cefe54e93f9 Mon Sep 17 00:00:00 2001 From: TOUFIKI Zakarya Date: Tue, 3 Dec 2024 10:21:36 +0100 Subject: [PATCH 5/9] Add Configuration part --- CHANGELOG.md | 6 ++++++ .../scripts/documentation/templates/module.md | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25d0a3c..18f500a 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.1 - 2024-12-03 + +### Add + +- Add a configuration part for action documentation + ### Fixed - Fix checkpoint for timestamps diff --git a/sekoia_automation/scripts/documentation/templates/module.md b/sekoia_automation/scripts/documentation/templates/module.md index 7d46a04..cec97d4 100644 --- a/sekoia_automation/scripts/documentation/templates/module.md +++ b/sekoia_automation/scripts/documentation/templates/module.md @@ -69,6 +69,14 @@ This module accepts no configuration. {{action.description}} +{%- if action.arguments.description %} + +**Configuration** + +{{action.arguments.description}} + +{%- endif -%} + {%- if action.arguments.properties %} **Arguments** From 630b57c5dabc09d61460d0476f776389aa6a5871 Mon Sep 17 00:00:00 2001 From: TOUFIKI Zakarya Date: Tue, 3 Dec 2024 10:45:26 +0100 Subject: [PATCH 6/9] Add the new version to pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 80a73bf..0cc2591 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.0" +version = "1.18.1" description = "SDK to create Sekoia.io playbook modules" license = "MIT" readme = "README.md" From 2fb3e92f9fc97445e08e6ee20c62e5ad68186137 Mon Sep 17 00:00:00 2001 From: TOUFIKI Zakarya Date: Tue, 3 Dec 2024 14:38:43 +0100 Subject: [PATCH 7/9] 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): From 56ed01420de93d03733080ae73e53a88de2a266f Mon Sep 17 00:00:00 2001 From: TOUFIKI Zakarya Date: Wed, 4 Dec 2024 10:00:00 +0100 Subject: [PATCH 8/9] Add the description to properties --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- sekoia_automation/scripts/documentation/templates/module.md | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 604237f..650d448 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.3 - 2024-12-04 + +### Fixed + +- Fix the configuration part in action documentation + ## 1.18.2 - 2024-12-03 ### Add diff --git a/pyproject.toml b/pyproject.toml index 665a12d..8ab1f19 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.2" +version = "1.18.3" description = "SDK to create Sekoia.io playbook modules" license = "MIT" readme = "README.md" diff --git a/sekoia_automation/scripts/documentation/templates/module.md b/sekoia_automation/scripts/documentation/templates/module.md index cec97d4..8d125d6 100644 --- a/sekoia_automation/scripts/documentation/templates/module.md +++ b/sekoia_automation/scripts/documentation/templates/module.md @@ -69,11 +69,11 @@ This module accepts no configuration. {{action.description}} -{%- if action.arguments.description %} +{%- if action.arguments.properties.description %} **Configuration** -{{action.arguments.description}} +{{action.arguments.properties.description}} {%- endif -%} From 0d5e33fb2cc3e09090b0662d8abdd5ae0bb60d66 Mon Sep 17 00:00:00 2001 From: Raphael Cohen Date: Wed, 4 Dec 2024 10:07:19 +0100 Subject: [PATCH 9/9] feat: Release 1.18.1 --- CHANGELOG.md | 15 ++------------- pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 650d448..9b376e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,22 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## 1.18.3 - 2024-12-04 +## 1.18.1 - 2024-12-04 -### Fixed - -- Fix the configuration part in action documentation - -## 1.18.2 - 2024-12-03 - -### Add +### Added - Add the support to list type for action response - -## 1.18.1 - 2024-12-03 - -### Add - - Add a configuration part for action documentation ### Fixed diff --git a/pyproject.toml b/pyproject.toml index 8ab1f19..0cc2591 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.3" +version = "1.18.1" description = "SDK to create Sekoia.io playbook modules" license = "MIT" readme = "README.md"