mirror of https://github.com/MISP/PyMISP
parent
56f624152e
commit
86a5d3acc7
|
@ -546,14 +546,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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue