Skip to content

Commit

Permalink
Merge pull request #269 from TheHive-Project/feature/alert-promotion
Browse files Browse the repository at this point in the history
Add parameters to method alert.promote_to_case()
  • Loading branch information
Kamforka authored Jan 13, 2023
2 parents 0593e35 + e47d5f5 commit a527e6d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
5 changes: 4 additions & 1 deletion tests/test_alert_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ def test_follow_and_unfollow(self, thehive: TheHiveApi, test_alert: OutputAlert)
def test_promote_to_case(self, thehive: TheHiveApi, test_alert: OutputAlert):
alert_id = test_alert["_id"]

case_from_alert = thehive.alert.promote_to_case(alert_id=alert_id)
case_from_alert = thehive.alert.promote_to_case(
alert_id=alert_id, fields={"title": "promoted title"}
)
promoted_alert = thehive.alert.get(alert_id=alert_id)
assert promoted_alert.get("caseId") == case_from_alert["_id"]
assert promoted_alert["title"] != case_from_alert["title"]

def test_merge_into_case(
self, thehive: TheHiveApi, test_alert: OutputAlert, test_case: OutputCase
Expand Down
7 changes: 5 additions & 2 deletions thehive4py/endpoints/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
InputAlert,
InputBulkUpdateAlert,
InputUpdateAlert,
InputPromoteAlert,
OutputAlert,
)
from thehive4py.types.case import OutputCase
Expand Down Expand Up @@ -59,11 +60,13 @@ def follow(self, alert_id: str) -> None:
def unfollow(self, alert_id: str) -> None:
self._session.make_request("POST", path=f"/api/v1/alert/{alert_id}/unfollow")

def promote_to_case(self, alert_id: str) -> OutputCase:
def promote_to_case(
self, alert_id: str, fields: InputPromoteAlert = {}
) -> OutputCase:
return self._session.make_request(
"POST",
path=f"/api/v1/alert/{alert_id}/case",
json={"placholder": ""}, # TODO: replace with optional body definition
json=fields,
)

def create_observable(
Expand Down
23 changes: 23 additions & 0 deletions thehive4py/types/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from thehive4py.types.custom_field import InputCustomFieldValue, OutputCustomFieldValue
from thehive4py.types.observable import InputObservable
from thehive4py.types.share import InputShare
from thehive4py.types.task import InputTask


class InputAlertRequired(TypedDict):
Expand Down Expand Up @@ -88,3 +90,24 @@ class InputUpdateAlert(TypedDict, total=False):

class InputBulkUpdateAlert(InputUpdateAlert):
ids: List[str]


class InputPromoteAlert(TypedDict, total=False):
title: str
description: str
severity: int
startDate: int
endDate: int
tags: List[str]
flag: bool
tlp: int
pap: int
status: str
summary: str
assignee: str
customFields: List[InputCustomFieldValue]
caseTemplate: str
tasks: List[InputTask]
sharingParameters: List[InputShare]
taskRule: str
observableRule: str

0 comments on commit a527e6d

Please sign in to comment.