mirror of https://github.com/MISP/PyMISPGalaxies
chg: allow to pass a list of galaxies as parameter
parent
c51e562a4a
commit
d76c6082ab
|
@ -22,6 +22,7 @@ class EncodeGalaxies(JSONEncoder):
|
|||
return obj.to_dict()
|
||||
return JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
class EncodeClusters(JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, (Cluster, ClusterValue, ClusterValueMeta)):
|
||||
|
@ -60,13 +61,17 @@ class Galaxy():
|
|||
|
||||
class Galaxies(collections.Mapping):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, galaxies=[]):
|
||||
if not galaxies:
|
||||
galaxies = []
|
||||
self.root_dir_galaxies = os.path.join(os.path.abspath(os.path.dirname(sys.modules['pymispgalaxies'].__file__)),
|
||||
'data', 'misp-galaxy', 'galaxies')
|
||||
self.galaxies = {}
|
||||
for galaxy_file in glob(os.path.join(self.root_dir_galaxies, '*.json')):
|
||||
with open(galaxy_file, 'r') as f:
|
||||
galaxy = json.load(f)
|
||||
galaxies.append(json.load(f))
|
||||
|
||||
self.galaxies = {}
|
||||
for galaxy in galaxies:
|
||||
self.galaxies[galaxy['name']] = Galaxy(galaxy)
|
||||
|
||||
def validate_with_schema(self):
|
||||
|
@ -239,13 +244,16 @@ class Cluster(collections.Mapping):
|
|||
|
||||
class Clusters(collections.Mapping):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, clusters=[]):
|
||||
if not clusters:
|
||||
clusters = []
|
||||
self.root_dir_clusters = os.path.join(os.path.abspath(os.path.dirname(sys.modules['pymispgalaxies'].__file__)),
|
||||
'data', 'misp-galaxy', 'clusters')
|
||||
self.clusters = {}
|
||||
for cluster_file in glob(os.path.join(self.root_dir_clusters, '*.json')):
|
||||
with open(cluster_file, 'r') as f:
|
||||
cluster = json.load(f)
|
||||
clusters.append(json.load(f))
|
||||
self.clusters = {}
|
||||
for cluster in clusters:
|
||||
self.clusters[cluster['type']] = Cluster(cluster)
|
||||
|
||||
def validate_with_schema(self):
|
||||
|
@ -267,7 +275,7 @@ class Clusters(collections.Mapping):
|
|||
cluster = self.get(cluster_type)
|
||||
value = cluster[cluster_value]
|
||||
return cluster, value
|
||||
except:
|
||||
except Exception:
|
||||
raise UnableToRevertMachinetag('The machinetag {} could not be found.'.format(machinetag))
|
||||
|
||||
def search(self, query):
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 9cfba28d3612621943b282ca434b26845f011c55
|
||||
Subproject commit 0eb6ab483280c943bfb3a6c19ce5ba1320f25c83
|
Loading…
Reference in New Issue