From 544547996096f512096d35861d8b1186da71de5c Mon Sep 17 00:00:00 2001 From: Tom King Date: Mon, 8 Feb 2021 11:52:08 +0000 Subject: [PATCH] chg: Don't parse the meta key into cluster elements on a MISPEvent, but allow users to manually perform this action --- pymisp/mispevent.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pymisp/mispevent.py b/pymisp/mispevent.py index f39cd2f..bc0253d 100644 --- a/pymisp/mispevent.py +++ b/pymisp/mispevent.py @@ -1195,6 +1195,7 @@ class MISPGalaxyCluster(AbstractMISP): super().__init__() self.Galaxy: MISPGalaxy self.GalaxyElement: List[MISPGalaxyClusterElement] = [] + self.meta = {} self.GalaxyClusterRelation: List[MISPGalaxyClusterRelation] = [] self.Org: MISPOrganisation self.Orgc: MISPOrganisation @@ -1218,8 +1219,18 @@ class MISPGalaxyCluster(AbstractMISP): def cluster_relations(self, cluster_relations: List[MISPGalaxyClusterRelation]): self.GalaxyClusterRelation = cluster_relations + def parse_meta_as_elements(self): + """Function to parse the meta field into GalaxyClusterElements""" + # Parse the cluster elements from the kwargs meta fields + for key, value in self.meta.items(): + # The meta will merge fields together, i.e. Two 'countries' will be a list, so split these up + if not isinstance(value, list): + value = [value] + for v in value: + self.add_cluster_element(key=key, value=v) + @property - def meta(self) -> Dict: + def elements_meta(self) -> Dict: """Function to return the galaxy cluster elements as a dictionary structure of lists that comes from a MISPGalaxy within a MISPEvent. Lossy, you lose the element ID """ @@ -1260,13 +1271,7 @@ class MISPGalaxyCluster(AbstractMISP): if 'uuid' in kwargs: self.uuid = kwargs.pop('uuid') if 'meta' in kwargs: - # Parse the cluster elements from the kwargs meta fields - for key, value in kwargs.pop('meta').items(): - # The meta will merge fields together, i.e. Two 'countries' will be a list, so split these up - if not isinstance(value, list): - value = [value] - for v in value: - self.add_cluster_element(key=key, value=v) + self.meta = kwargs.pop('meta') if 'Galaxy' in kwargs: self.Galaxy = MISPGalaxy() self.Galaxy.from_dict(**kwargs.pop('Galaxy'))