new: hard delete flag for objects

Related: https://github.com/MISP/PyMISP/issues/666
pull/694/head
Raphaël Vinot 2020-12-03 14:50:22 +01:00
parent d97e7993bb
commit 371fb57d92
2 changed files with 15 additions and 4 deletions

View File

@ -454,14 +454,18 @@ class PyMISP:
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

View File

@ -1244,7 +1244,14 @@ class TestComprehensive(unittest.TestCase):
# 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)