Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.26.0
-------
- Raise AlertConflictError when fetching an alert by id without an environment returns 409 (previously masked as AlertNotFoundError)

1.25.1
-------
- Make request method kwargs only and add params
Expand Down
2 changes: 1 addition & 1 deletion intezer_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.25.1'
__version__ = '1.26.0'
7 changes: 5 additions & 2 deletions intezer_sdk/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import hashlib
import json
import time
from http import HTTPStatus
from io import BytesIO
from typing import Any
from typing import BinaryIO
Expand Down Expand Up @@ -314,11 +315,12 @@ def check_status(self) -> AlertStatusCode:
Refresh the alert data from the Intezer Platform API - overrides current data (if exists) with the new data.

:return: The updated status of the alert.

"""
try:
alert, status = self._api.get_alert_by_alert_id(alert_id=self.alert_id, environment=self.environment)
except requests.HTTPError:
except requests.HTTPError as e:
if e.response is not None and e.response.status_code == HTTPStatus.CONFLICT:
raise errors.AlertConflictError(self.alert_id)
self.status = AlertStatusCode.NOT_FOUND
raise errors.AlertNotFoundError(self.alert_id)

Expand Down Expand Up @@ -374,6 +376,7 @@ def from_id(cls,
:param timeout: The timeout for the wait operation.
:raises intezer_sdk.errors.AlertNotFound: If the alert was not found.
:raises intezer_sdk.errors.AlertInProgressError: If the alert is still being processed.
:raises intezer_sdk.errors.AlertConflictError: If the alert is ambiguous across environments and no environment was provided.
:return: The Alert instance, with the updated alert data.
"""
new_alert = cls(alert_id=alert_id, environment=environment or None, api=api)
Expand Down
7 changes: 7 additions & 0 deletions intezer_sdk/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ def __init__(self, alert_id: str):
super().__init__(f'The given alert does not exist - {alert_id}')


class AlertConflictError(AlertError):
def __init__(self, alert_id: str):
super().__init__(
f'The alert {alert_id} is ambiguous across environments - please specify an environment'
)


class InvalidAlertArgumentError(AlertError):
def __init__(self, message: str):
super().__init__(message)
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ def test_alert_from_id(self):
self.assertEqual(alert.alert_id, 'alert_id')


def test_alert_from_id_raises_conflict_when_environment_is_ambiguous(self):
# Arrange
with responses.RequestsMock() as mock:
mock.add('GET',
url=f'{self.full_url}/alerts/get-by-id',
status=HTTPStatus.CONFLICT,
json={'error': 'Alert exists in multiple environments'})
# Act & Assert
with self.assertRaises(errors.AlertConflictError):
Alert.from_id('alert_id')

def test_alert_from_id_waits_from_completion(self):
# Arrange
with responses.RequestsMock() as mock:
Expand Down
Loading