Skip to content

Commit

Permalink
Merge branch 'main' into fix/connector_workflow
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	pyproject.toml
  • Loading branch information
vg-svitla committed Dec 10, 2024
2 parents 6c65296 + 7c6d61f commit 604ce4f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 10 deletions.
39 changes: 38 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,51 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## 1.19.0 - 2024-11-28
## 1.19.0 - 2024-12-10

### Changed

- Improvements for AsyncConnector.
- Improvements for Async Http workflow
- Remove duplicated parts and make the code more uniform for async http workflow

## 1.18.1 - 2024-12-04

### Added

- Add the support to list type for action response
- Add a configuration part for action documentation

### Fixed

- Fix checkpoint for timestamps

## 1.18.0 - 2024-11-26

### Changed

- Add additional values to log events sent to the API
- In Generic actions, in case of error use the message from the response if available

## 1.17.2 - 2024-11-06

### Fixed

- Fix callback URL file for account validation

## 1.17.1 - 2024-11-04

### Fixed

- Change the way to handle docker image information when publishing a module
- Fix the module synchronization script

## 1.17.0 - 2024-11-04

### Added

- Add account validation (beta)

## 1.16.1 - 2024-10-30

### Changed
Expand Down
10 changes: 10 additions & 0 deletions sekoia_automation/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions sekoia_automation/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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


Expand Down
8 changes: 8 additions & 0 deletions sekoia_automation/scripts/documentation/templates/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ This module accepts no configuration.

{{action.description}}

{%- if action.arguments.properties.description %}

**Configuration**

{{action.arguments.properties.description}}

{%- endif -%}

{%- if action.arguments.properties %}

**Arguments**
Expand Down
18 changes: 18 additions & 0 deletions tests/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 604ce4f

Please sign in to comment.