fix: cosmetic changes, fix mypy

pull/749/head
Raphaël Vinot 2021-03-02 12:21:59 +01:00
parent d3bdb46587
commit 9f7282e8f4
2 changed files with 14 additions and 11 deletions

View File

@ -1332,7 +1332,7 @@ class PyMISP:
g.from_dict(**galaxy_j, withCluster=withCluster) g.from_dict(**galaxy_j, withCluster=withCluster)
return g return g
def search_galaxy_clusters(self, galaxy: Union[MISPGalaxy, int, str, UUID], context: str = "all", searchall: str = None, pythonify: bool = False) -> Union[List[Dict], List[MISPGalaxyCluster]]: def search_galaxy_clusters(self, galaxy: Union[MISPGalaxy, int, str, UUID], context: str = "all", searchall: str = None, pythonify: bool = False) -> Union[Dict, List[MISPGalaxyCluster]]:
"""Searches the galaxy clusters within a specific galaxy """Searches the galaxy clusters within a specific galaxy
:param galaxy: The MISPGalaxy you wish to search in :param galaxy: The MISPGalaxy you wish to search in
@ -1342,9 +1342,9 @@ class PyMISP:
""" """
galaxy_id = get_uuid_or_id_from_abstract_misp(galaxy) galaxy_id = get_uuid_or_id_from_abstract_misp(galaxy)
allowed_context_types = ["all", "default", "custom", "org", "deleted"] allowed_context_types: List[str] = ["all", "default", "custom", "org", "deleted"]
if context not in allowed_context_types: if context not in allowed_context_types:
raise PyMISPError(f"The context must be one of {allowed_context_types.join(', ')}") raise PyMISPError(f"The context must be one of {', '.join(allowed_context_types)}")
kw_params = {"context": context} kw_params = {"context": context}
if searchall: if searchall:
kw_params["searchall"] = searchall kw_params["searchall"] = searchall
@ -1432,7 +1432,7 @@ class PyMISP:
response = self._check_json_response(r) response = self._check_json_response(r)
return response return response
def fork_galaxy_cluster(self, galaxy: Union[MISPGalaxy, int, str, UUID], galaxy_cluster: Union[MISPGalaxyClusterRelation, int, str, UUID], pythonify: bool = False) -> Union[Dict, MISPGalaxyCluster]: def fork_galaxy_cluster(self, galaxy: Union[MISPGalaxy, int, str, UUID], galaxy_cluster: MISPGalaxyCluster, pythonify: bool = False) -> Union[Dict, MISPGalaxyCluster]:
"""Forks an existing galaxy cluster, creating a new one with matching attributes """Forks an existing galaxy cluster, creating a new one with matching attributes
:param galaxy: The galaxy (or galaxy ID) where the cluster you want to fork resides :param galaxy: The galaxy (or galaxy ID) where the cluster you want to fork resides
@ -1456,7 +1456,7 @@ class PyMISP:
gc.from_dict(**cluster_j) gc.from_dict(**cluster_j)
return gc return gc
def delete_galaxy_cluster(self, galaxy_cluster: Union[MISPGalaxyCluster, id, str, UUID], hard=False) -> Dict: def delete_galaxy_cluster(self, galaxy_cluster: Union[MISPGalaxyCluster, int, str, UUID], hard=False) -> Dict:
"""Deletes a galaxy cluster from MISP """Deletes a galaxy cluster from MISP
:param galaxy_cluster: The MISPGalaxyCluster you wish to delete from MISP :param galaxy_cluster: The MISPGalaxyCluster you wish to delete from MISP

View File

@ -1069,6 +1069,9 @@ class MISPGalaxyClusterElement(AbstractMISP):
:type value: str :type value: str
""" """
key: str
value: str
def __repr__(self) -> str: def __repr__(self) -> str:
if hasattr(self, 'key') and hasattr(self, 'value'): if hasattr(self, 'key') and hasattr(self, 'value'):
return '<{self.__class__.__name__}(key={self.key}, value={self.value})'.format(self=self) return '<{self.__class__.__name__}(key={self.key}, value={self.value})'.format(self=self)
@ -1117,7 +1120,7 @@ class MISPGalaxyClusterRelation(AbstractMISP):
self.referenced_galaxy_cluster_uuid: uuid self.referenced_galaxy_cluster_uuid: uuid
self.distribution: int = 0 self.distribution: int = 0
self.referenced_galaxy_cluster_type: str self.referenced_galaxy_cluster_type: str
self.Tag: MISPTag = [] self.Tag: List[MISPTag] = []
def from_dict(self, **kwargs): def from_dict(self, **kwargs):
# Default values for a valid event to send to a MISP instance # Default values for a valid event to send to a MISP instance
@ -1212,7 +1215,7 @@ class MISPGalaxyCluster(AbstractMISP):
self.GalaxyElement = cluster_elements self.GalaxyElement = cluster_elements
@property @property
def cluster_relations(self) -> MISPGalaxyClusterRelation: def cluster_relations(self) -> List[MISPGalaxyClusterRelation]:
return self.GalaxyClusterRelation return self.GalaxyClusterRelation
@cluster_relations.setter @cluster_relations.setter
@ -1564,14 +1567,14 @@ class MISPEvent(AbstractMISP):
def related_events(self) -> List['MISPEvent']: def related_events(self) -> List['MISPEvent']:
return self.RelatedEvent return self.RelatedEvent
@property
def objects(self) -> List[MISPObject]:
return self.Object
@property @property
def galaxies(self) -> List[MISPGalaxy]: def galaxies(self) -> List[MISPGalaxy]:
return self.Galaxy return self.Galaxy
@property
def objects(self) -> List[MISPObject]:
return self.Object
@objects.setter @objects.setter
def objects(self, objects: List[MISPObject]): def objects(self, objects: List[MISPObject]):
if all(isinstance(x, MISPObject) for x in objects): if all(isinstance(x, MISPObject) for x in objects):