mirror of https://github.com/MISP/PyMISP
new: Allow to get just event metadata after add_event and edit_event
parent
495af1fd9c
commit
5e4dd2b974
|
@ -316,13 +316,14 @@ class PyMISP:
|
|||
r = self._prepare_request('HEAD', f'events/view/{event_id}')
|
||||
return self._check_head_response(r)
|
||||
|
||||
def add_event(self, event: MISPEvent, pythonify: bool = False) -> Union[Dict, MISPEvent]:
|
||||
def add_event(self, event: MISPEvent, pythonify: bool = False, metadata: bool = False) -> Union[Dict, MISPEvent]:
|
||||
"""Add a new event on a MISP instance
|
||||
|
||||
:param event: event to add
|
||||
:param pythonify: Returns a PyMISP Object instead of the plain json output
|
||||
:param metadata: Return just event metadata after successful creating
|
||||
"""
|
||||
r = self._prepare_request('POST', 'events/add', data=event)
|
||||
r = self._prepare_request('POST', 'events/add' + '/metadata:1' if metadata else '', data=event)
|
||||
new_event = self._check_json_response(r)
|
||||
if not (self.global_pythonify or pythonify) or 'errors' in new_event:
|
||||
return new_event
|
||||
|
@ -330,18 +331,20 @@ class PyMISP:
|
|||
e.load(new_event)
|
||||
return e
|
||||
|
||||
def update_event(self, event: MISPEvent, event_id: Optional[int] = None, pythonify: bool = False) -> Union[Dict, MISPEvent]:
|
||||
def update_event(self, event: MISPEvent, event_id: Optional[int] = None, pythonify: bool = False,
|
||||
metadata: bool = False) -> Union[Dict, MISPEvent]:
|
||||
"""Update an event on a MISP instance'''
|
||||
|
||||
:param event: event to update
|
||||
:param event_id: ID of event to update
|
||||
:param pythonify: Returns a PyMISP Object instead of the plain json output
|
||||
:param metadata: Return just event metadata after successful update
|
||||
"""
|
||||
if event_id is None:
|
||||
eid = get_uuid_or_id_from_abstract_misp(event)
|
||||
else:
|
||||
eid = get_uuid_or_id_from_abstract_misp(event_id)
|
||||
r = self._prepare_request('POST', f'events/edit/{eid}', data=event)
|
||||
r = self._prepare_request('POST', f'events/edit/{eid}' + '/metadata:1' if metadata else '', data=event)
|
||||
updated_event = self._check_json_response(r)
|
||||
if not (self.global_pythonify or pythonify) or 'errors' in updated_event:
|
||||
return updated_event
|
||||
|
|
|
@ -886,6 +886,19 @@ class TestComprehensive(unittest.TestCase):
|
|||
self.admin_misp_connector.delete_event(first)
|
||||
self.admin_misp_connector.delete_event(second)
|
||||
|
||||
def test_event_add_update_metadata(self):
|
||||
event = self.create_simple_event()
|
||||
event.add_attribute('ip-src', '9.9.9.9')
|
||||
try:
|
||||
response = self.user_misp_connector.add_event(event, metadata=True)
|
||||
self.assertEqual(len(response.attributes), 0) # response should contains zero attributes
|
||||
|
||||
event.info = "New name"
|
||||
response = self.user_misp_connector.update_event(event, metadata=True)
|
||||
self.assertEqual(len(response.attributes), 0) # response should contains zero attributes
|
||||
finally: # cleanup
|
||||
self.admin_misp_connector.delete_event(event)
|
||||
|
||||
def test_extend_event(self):
|
||||
first = self.create_simple_event()
|
||||
first.info = 'parent event'
|
||||
|
|
Loading…
Reference in New Issue