mirror of https://github.com/MISP/PyMISPGalaxies
chg: Add to_json helpers
parent
58069d1a67
commit
4e15ac5d79
|
@ -50,6 +50,9 @@ class Galaxy():
|
|||
self.version = self.galaxy['version']
|
||||
self.uuid = self.galaxy['uuid']
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(self, cls=EncodeGalaxies)
|
||||
|
||||
def to_dict(self):
|
||||
return {'type': self.type, 'name': self.name, 'description': self.description,
|
||||
'version': self.version, 'uuid': self.uuid, 'icon': self.icon}
|
||||
|
@ -109,6 +112,9 @@ class ClusterValueMeta():
|
|||
# defined on the schema
|
||||
self.additional_properties = m
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(self, cls=EncodeClusters)
|
||||
|
||||
def to_dict(self):
|
||||
to_return = {}
|
||||
if self.type:
|
||||
|
@ -165,6 +171,9 @@ class ClusterValue():
|
|||
return None
|
||||
return ClusterValueMeta(m)
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(self, cls=EncodeClusters)
|
||||
|
||||
def to_dict(self):
|
||||
to_return = {'value': self.value}
|
||||
if self.description:
|
||||
|
@ -217,6 +226,9 @@ class Cluster(collections.Mapping):
|
|||
def __iter__(self):
|
||||
return iter(self.cluster_values)
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(self, cls=EncodeClusters)
|
||||
|
||||
def to_dict(self):
|
||||
to_return = {'name': self.name, 'type': self.type, 'source': self.source,
|
||||
'authors': self.authors, 'description': self.description,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import unittest
|
||||
from pymispgalaxies import Galaxies, Clusters, UnableToRevertMachinetag, EncodeGalaxies, EncodeClusters
|
||||
from pymispgalaxies import Galaxies, Clusters, UnableToRevertMachinetag
|
||||
from glob import glob
|
||||
import os
|
||||
import json
|
||||
|
@ -69,5 +69,7 @@ class TestPyMISPGalaxies(unittest.TestCase):
|
|||
self.assertIsNot(len(c), 0)
|
||||
|
||||
def test_json(self):
|
||||
for g in self.galaxies.values():
|
||||
g.to_json()
|
||||
for c in self.clusters.values():
|
||||
json.dumps(c, cls=EncodeClusters)
|
||||
c.to_json()
|
||||
|
|
Loading…
Reference in New Issue