mirror of https://github.com/MISP/PyMISP
chg: Improve sharing groups, bring back organsations included and ability to get specific SG
parent
0a3f2e68ef
commit
c120db02b8
|
@ -1921,6 +1921,21 @@ class PyMISP:
|
||||||
to_return.append(s)
|
to_return.append(s)
|
||||||
return to_return
|
return to_return
|
||||||
|
|
||||||
|
def get_sharing_group(self, sharing_group: Union[MISPSharingGroup, int, str, UUID], pythonify: bool = False) -> Union[Dict, MISPSharingGroup]:
|
||||||
|
"""Get a sharing group
|
||||||
|
|
||||||
|
:param sharing_group: sharing group to find
|
||||||
|
:param pythonify: Returns a PyMISP Object instead of the plain json output
|
||||||
|
"""
|
||||||
|
sharing_group_id = get_uuid_or_id_from_abstract_misp(sharing_group)
|
||||||
|
r = self._prepare_request('GET', f'sharing_groups/view/{sharing_group_id}')
|
||||||
|
sharing_group = self._check_json_response(r)
|
||||||
|
if not (self.global_pythonify or pythonify) or 'errors' in sharing_group:
|
||||||
|
return sharing_group
|
||||||
|
s = MISPSharingGroup()
|
||||||
|
s.from_dict(**sharing_group)
|
||||||
|
return s
|
||||||
|
|
||||||
def add_sharing_group(self, sharing_group: MISPSharingGroup, pythonify: bool = False) -> Union[Dict, MISPSharingGroup]:
|
def add_sharing_group(self, sharing_group: MISPSharingGroup, pythonify: bool = False) -> Union[Dict, MISPSharingGroup]:
|
||||||
"""Add a new sharing group
|
"""Add a new sharing group
|
||||||
|
|
||||||
|
|
|
@ -126,12 +126,40 @@ class MISPOrganisation(AbstractMISP):
|
||||||
|
|
||||||
|
|
||||||
class MISPSharingGroup(AbstractMISP):
|
class MISPSharingGroup(AbstractMISP):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.SharingGroupOrg: List[MISPOrganisation] = []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def orgs(self) -> List[MISPOrganisation]:
|
||||||
|
return self.SharingGroupOrg
|
||||||
|
|
||||||
|
@orgs.setter
|
||||||
|
def orgs(self, orgs: List[MISPOrganisation]):
|
||||||
|
"""Set a list of prepared MISPSighting."""
|
||||||
|
if all(isinstance(x, MISPSighting) for x in orgs):
|
||||||
|
self.SharingGroupOrg = orgs
|
||||||
|
else:
|
||||||
|
raise PyMISPError('All the attributes have to be of type MISPOrganisation.')
|
||||||
|
|
||||||
|
def add_org(self, org):
|
||||||
|
misp_org = MISPOrganisation()
|
||||||
|
misp_org.from_dict(**org)
|
||||||
|
self.SharingGroupOrg.append(misp_org)
|
||||||
|
return misp_org
|
||||||
|
|
||||||
def from_dict(self, **kwargs):
|
def from_dict(self, **kwargs):
|
||||||
|
if 'SharingGroupOrg' in kwargs:
|
||||||
|
[self.add_org(org) for org in kwargs.pop('SharingGroupOrg')]
|
||||||
if 'SharingGroup' in kwargs:
|
if 'SharingGroup' in kwargs:
|
||||||
kwargs = kwargs['SharingGroup']
|
kwargs = kwargs['SharingGroup']
|
||||||
super().from_dict(**kwargs)
|
super().from_dict(**kwargs)
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
if hasattr(self, 'name'):
|
||||||
|
return f'<{self.__class__.__name__}(name={self.name})'
|
||||||
|
return f'<{self.__class__.__name__}(NotInitialized)'
|
||||||
|
|
||||||
|
|
||||||
class MISPShadowAttribute(AbstractMISP):
|
class MISPShadowAttribute(AbstractMISP):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue