Skip to content

Commit

Permalink
new: hard delete flag for objects
Browse files Browse the repository at this point in the history
Related: #666
  • Loading branch information
Rafiot committed Dec 3, 2020
1 parent 649e068 commit 9344cd3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pymisp/api.py
Expand Up @@ -450,14 +450,18 @@ def update_object(self, misp_object: MISPObject, object_id: Optional[int] = None
o.from_dict(**updated_object)
return o

def delete_object(self, misp_object: Union[MISPObject, int, str, UUID]) -> Dict:
def delete_object(self, misp_object: Union[MISPObject, int, str, UUID], hard: bool = False) -> Dict:
"""Delete an object from a MISP instance
:param misp_object: object to delete
:param hard: flag for hard delete
"""
object_id = get_uuid_or_id_from_abstract_misp(misp_object)
response = self._prepare_request('POST', f'objects/delete/{object_id}')
return self._check_json_response(response)
data = {}
if hard:
data['hard'] = 1
r = self._prepare_request('POST', f'objects/delete/{object_id}', data=data)
return self._check_json_response(r)

def add_object_reference(self, misp_object_reference: MISPObjectReference, pythonify: bool = False) -> Union[Dict, MISPObjectReference]:
"""Add a reference to an object
Expand Down
9 changes: 8 additions & 1 deletion tests/testlive_comprehensive.py
Expand Up @@ -1237,7 +1237,14 @@ def test_update_object(self):

# Test delete object
r = self.user_misp_connector.delete_object(second.objects[0])
self.assertEqual(r['message'], 'Object deleted')
self.assertEqual(r['message'], 'Object deleted', r)
new_second = self.admin_misp_connector.get_event(second, deleted=[0, 1], pythonify=True)
self.assertEqual(len(new_second.objects), 1)
# Hard delete
response = self.admin_misp_connector.delete_object(second.objects[0], hard=True)
self.assertEqual(response['message'], 'Object deleted')
new_second = self.admin_misp_connector.get_event(second, deleted=[0, 1], pythonify=True)
self.assertEqual(len(new_second.objects), 0)
finally:
# Delete event
self.admin_misp_connector.delete_event(first)
Expand Down

1 comment on commit 9344cd3

@chrisinmtown
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick action here!

Please sign in to comment.