chg: Add in add_cluster function and ability to search clusters within a galaxy

pull/682/head
Tom King 2021-01-25 13:18:12 +00:00
parent cff7e7b285
commit cc102675bb
1 changed files with 29 additions and 0 deletions

View File

@ -1208,6 +1208,25 @@ class PyMISP:
g.from_dict(**galaxy_j, withCluster=withCluster)
return g
def search_galaxy_clusters(self, galaxy: Union[MISPGalaxy, int, str, UUID], context: str = "all", searchall: str = None, pythonify: bool = False) -> Union[Dict, List[MISPGalaxyCluster]]:
galaxy_id = get_uuid_or_id_from_abstract_misp(galaxy)
allowed_context_types = ["all", "default", "custom", "org", "deleted"]
if context not in allowed_context_types:
raise PyMISPError(f"The context must be one of {allowed_context_types.join(', ')}")
kw_params = {"context": context}
if searchall:
kw_params["searchall"] = searchall
r = self._prepare_request('GET', f"galaxy_clusters/index/{galaxy_id}", kw_params=kw_params)
clusters_j = self._check_json_response(r)
if not (self.global_pythonify or pythonify) or 'errors' in clusters_j:
return clusters_j
response = []
for cluster in clusters_j:
c = MISPGalaxyCluster()
c.from_dict(**cluster)
response.append(c)
return response
def update_galaxies(self) -> Dict:
"""Update all the galaxies."""
response = self._prepare_request('POST', 'galaxies/update')
@ -1223,6 +1242,16 @@ class PyMISP:
gc.from_dict(**cluster_j)
return gc
def add_galaxy_cluster(self, galaxy: MISPGalaxy, galaxy_cluster: MISPGalaxyCluster, pythonify: bool = False) -> Union[Dict, MISPGalaxyCluster]:
galaxy_id = get_uuid_or_id_from_abstract_misp(galaxy)
r = self._prepare_request('POST', f'galaxy_clusters/add/{galaxy_id}', data=galaxy_cluster)
cluster_j = self._check_json_response(r)
if not (self.global_pythonify or pythonify) or 'errors' in cluster_j:
return cluster_j
gc = MISPGalaxyCluster()
gc.from_dict(**cluster_j)
return gc
def update_galaxy_cluster(self, galaxy_cluster: MISPGalaxyCluster, pythonify: bool = False) -> Union[Dict, MISPGalaxyCluster]:
"""Update a custom galaxy cluster."""
if galaxy_cluster.default: