new: Method `update_sharing_group`

pull/761/head
Jakub Onderka 2021-06-22 17:48:53 +02:00
parent fa536ee41e
commit 77eeb10abb
2 changed files with 23 additions and 0 deletions

View File

@ -1921,6 +1921,25 @@ class PyMISP:
s.from_dict(**sharing_group_j)
return s
def update_sharing_group(self, sharing_group: Union[MISPSharingGroup, dict], sharing_group_id: Optional[int] = None, pythonify: bool = False) -> Union[Dict, MISPSharingGroup]:
"""Update sharing group parameters
:param sharing_group: MISP Sharing Group
:param sharing_group_id Sharing group ID
:param pythonify: Returns a PyMISP Object instead of the plain json output
"""
if sharing_group_id is None:
sid = get_uuid_or_id_from_abstract_misp(sharing_group)
else:
sid = get_uuid_or_id_from_abstract_misp(sharing_group_id)
r = self._prepare_request('POST', f'sharing_groups/edit/{sid}', data=sharing_group)
updated_sharing_group = self._check_json_response(r)
if not (self.global_pythonify or pythonify) or 'errors' in updated_sharing_group:
return updated_sharing_group
s = MISPSharingGroup()
s.from_dict(**updated_sharing_group)
return s
def delete_sharing_group(self, sharing_group: Union[MISPSharingGroup, int, str, UUID]) -> Dict:
"""Delete a sharing group

View File

@ -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')
# Change releasability
r = self.admin_misp_connector.update_sharing_group({"releasability": "Testing updated"}, sharing_group)
self.assertEqual(sharing_group.releasability, 'Testing updated')
# add org
r = self.admin_misp_connector.add_org_to_sharing_group(sharing_group,
self.test_org, extend=True)