mirror of https://github.com/MISP/PyMISP
Merge pull request #759 from JakubOnderka/exists-method
New methods `sharing_group_exists` and `organisation_exists`pull/770/head
commit
862459ddcf
|
@ -1921,6 +1921,15 @@ class PyMISP:
|
|||
s.from_dict(**sharing_group_j)
|
||||
return s
|
||||
|
||||
def sharing_group_exists(self, sharing_group: Union[MISPSharingGroup, int, str, UUID]) -> bool:
|
||||
"""Fast check if sharing group exists.
|
||||
|
||||
:param sharing_group: Sharing group to check
|
||||
"""
|
||||
sharing_group_id = get_uuid_or_id_from_abstract_misp(sharing_group)
|
||||
r = self._prepare_request('HEAD', f'sharing_groups/view/{sharing_group_id}')
|
||||
return self._check_head_response(r)
|
||||
|
||||
def delete_sharing_group(self, sharing_group: Union[MISPSharingGroup, int, str, UUID]) -> Dict:
|
||||
"""Delete a sharing group
|
||||
|
||||
|
@ -2020,6 +2029,15 @@ class PyMISP:
|
|||
o.from_dict(**organisation_j)
|
||||
return o
|
||||
|
||||
def organisation_exists(self, organisation: Union[MISPOrganisation, int, str, UUID]) -> bool:
|
||||
"""Fast check if organisation exists.
|
||||
|
||||
:param organisation: Organisation to check
|
||||
"""
|
||||
organisation_id = get_uuid_or_id_from_abstract_misp(organisation)
|
||||
r = self._prepare_request('HEAD', f'organisations/view/{organisation_id}')
|
||||
return self._check_head_response(r)
|
||||
|
||||
def add_organisation(self, organisation: MISPOrganisation, pythonify: bool = False) -> Union[Dict, MISPOrganisation]:
|
||||
"""Add an organisation
|
||||
|
||||
|
|
|
@ -2077,6 +2077,10 @@ class TestComprehensive(unittest.TestCase):
|
|||
sharing_group = self.admin_misp_connector.add_sharing_group(sg, pythonify=True)
|
||||
self.assertEqual(sharing_group.name, 'Testcases SG')
|
||||
self.assertEqual(sharing_group.releasability, 'Testing')
|
||||
# Test `sharing_group_exists` method
|
||||
self.assertTrue(self.admin_misp_connector.sharing_group_exists(sharing_group))
|
||||
self.assertTrue(self.admin_misp_connector.sharing_group_exists(sharing_group.id))
|
||||
self.assertTrue(self.admin_misp_connector.sharing_group_exists(sharing_group.uuid))
|
||||
# add org
|
||||
r = self.admin_misp_connector.add_org_to_sharing_group(sharing_group,
|
||||
self.test_org, extend=True)
|
||||
|
@ -2125,6 +2129,10 @@ class TestComprehensive(unittest.TestCase):
|
|||
r = self.admin_misp_connector.delete_sharing_group(sharing_group.id)
|
||||
self.assertEqual(r['message'], 'SharingGroup deleted')
|
||||
|
||||
self.assertFalse(self.admin_misp_connector.sharing_group_exists(sharing_group))
|
||||
self.assertFalse(self.admin_misp_connector.sharing_group_exists(sharing_group.id))
|
||||
self.assertFalse(self.admin_misp_connector.sharing_group_exists(sharing_group.uuid))
|
||||
|
||||
def test_feeds(self):
|
||||
# Add
|
||||
feed = MISPFeed()
|
||||
|
|
Loading…
Reference in New Issue