diff --git a/pymispgalaxies/api.py b/pymispgalaxies/api.py index 46bdcd5..6918ea4 100644 --- a/pymispgalaxies/api.py +++ b/pymispgalaxies/api.py @@ -177,6 +177,7 @@ class ClusterValue(): self.searchable.append(self.uuid) if self.meta and self.meta.synonyms: self.searchable += self.meta.synonyms + self.searchable = list(set(self.searchable)) def __init_meta(self, m): if not m: @@ -219,11 +220,15 @@ class Cluster(collections.Mapping): raise PyMISPGalaxiesError("Duplicate value ({}) in cluster: {}".format(new_cluster_value.value, self.name)) self.cluster_values[new_cluster_value.value] = new_cluster_value - def search(self, query): + def search(self, query, return_tags=False): matching = [] for v in self.values(): if [s for s in v.searchable if query.lower() in s.lower()]: - matching.append(v) + if return_tags: + matching.append('misp-galaxy:{}="{}"'.format(self.type, v.value)) + pass + else: + matching.append(v) return matching def machinetags(self): @@ -291,10 +296,10 @@ class Clusters(collections.Mapping): except Exception: raise UnableToRevertMachinetag('The machinetag {} could not be found.'.format(machinetag)) - def search(self, query): + def search(self, query, return_tags=False): to_return = [] for cluster in self.values(): - values = cluster.search(query) + values = cluster.search(query, return_tags) if not values: continue to_return.append((cluster, values)) diff --git a/pymispgalaxies/data/misp-galaxy b/pymispgalaxies/data/misp-galaxy index 3087747..e5939e3 160000 --- a/pymispgalaxies/data/misp-galaxy +++ b/pymispgalaxies/data/misp-galaxy @@ -1 +1 @@ -Subproject commit 308774755c8d5b01bfd30ea0ab868c83fdfdd715 +Subproject commit e5939e3248591c0e454a8a25a9cbf21f6318541d diff --git a/tests/tests.py b/tests/tests.py index 53b2764..d7f24e8 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- import unittest @@ -7,6 +7,7 @@ from glob import glob import os import json from collections import Counter +import warnings class TestPyMISPGalaxies(unittest.TestCase): @@ -16,6 +17,16 @@ class TestPyMISPGalaxies(unittest.TestCase): self.clusters = Clusters(skip_duplicates=True) self.maxDiff = None + def test_searchable(self): + for cluster in self.clusters.values(): + all_searchable = [] + for c_values in cluster.values(): + all_searchable += c_values.searchable + count = Counter(all_searchable) + for k, v in count.items(): + if v != 1: + warnings.warn(f'Duplicate on {cluster.type}: {k}') + def test_duplicates(self): has_duplicates = False for name, c in self.clusters.items():