mirror of https://github.com/MISP/PyMISP
fix: normalizing the outputs
parent
f4c0b92305
commit
8b8459ce53
|
@ -57,6 +57,14 @@ class Analysis(Enum):
|
|||
completed = 2
|
||||
|
||||
|
||||
def _int_to_str(d):
|
||||
# transform all integer back to string
|
||||
for k, v in d.items():
|
||||
if isinstance(v, (int, float)) and not isinstance(v, bool):
|
||||
d[k] = str(v)
|
||||
return d
|
||||
|
||||
|
||||
class MISPEncode(JSONEncoder):
|
||||
|
||||
def default(self, obj):
|
||||
|
@ -151,6 +159,7 @@ class AbstractMISP(collections.MutableMapping):
|
|||
else:
|
||||
val = self._datetime_to_timestamp(val)
|
||||
to_return[attribute] = val
|
||||
to_return = _int_to_str(to_return)
|
||||
return to_return
|
||||
|
||||
def jsonable(self):
|
||||
|
@ -214,7 +223,7 @@ class AbstractMISP(collections.MutableMapping):
|
|||
"""Convert a datetime.datetime object to a timestamp (int)"""
|
||||
if isinstance(d, (int, str)) or (sys.version_info < (3, 0) and isinstance(d, unicode)):
|
||||
# Assume we already have a timestamp
|
||||
return d
|
||||
return int(d)
|
||||
if sys.version_info >= (3, 3):
|
||||
return int(d.timestamp())
|
||||
else:
|
||||
|
|
|
@ -247,7 +247,6 @@ class MISPAttribute(AbstractMISP):
|
|||
to_return = super(MISPAttribute, self).to_dict()
|
||||
if to_return.get('data'):
|
||||
to_return['data'] = base64.b64encode(self.data.getvalue()).decode()
|
||||
to_return = _int_to_str(to_return)
|
||||
return to_return
|
||||
|
||||
def _prepare_new_malware_sample(self):
|
||||
|
@ -573,9 +572,7 @@ class MISPEvent(AbstractMISP):
|
|||
if to_return.get('publish_timestamp'):
|
||||
to_return['publish_timestamp'] = self._datetime_to_timestamp(self.publish_timestamp)
|
||||
|
||||
to_return = _int_to_str(to_return)
|
||||
to_return = {'Event': to_return}
|
||||
return to_return
|
||||
return {'Event': _int_to_str(to_return)}
|
||||
|
||||
def add_proposal(self, shadow_attribute=None, **kwargs):
|
||||
"""Alias for add_shadow_attribute"""
|
||||
|
|
|
@ -37,12 +37,12 @@
|
|||
}
|
||||
],
|
||||
"description": "Whois records information for a domain name or an IP address.",
|
||||
"distribution": 5,
|
||||
"distribution": "5",
|
||||
"meta-category": "network",
|
||||
"name": "whois",
|
||||
"sharing_group_id": 0,
|
||||
"sharing_group_id": "0",
|
||||
"template_uuid": "429faea1-34ff-47af-8a00-7c62d3be5a6a",
|
||||
"template_version": 10,
|
||||
"template_version": "10",
|
||||
"uuid": "a"
|
||||
}
|
||||
],
|
||||
|
|
|
@ -26,12 +26,12 @@
|
|||
}
|
||||
],
|
||||
"description": "File object describing a file with meta-information",
|
||||
"distribution": 5,
|
||||
"distribution": "5",
|
||||
"meta-category": "file",
|
||||
"name": "file",
|
||||
"sharing_group_id": 0,
|
||||
"sharing_group_id": "0",
|
||||
"template_uuid": "688c46fb-5edb-40a3-8273-1af7923e2215",
|
||||
"template_version": 13,
|
||||
"template_version": "13",
|
||||
"uuid": "a"
|
||||
},
|
||||
{
|
||||
|
@ -46,12 +46,12 @@
|
|||
}
|
||||
],
|
||||
"description": "url object describes an url along with its normalized field (like extracted using faup parsing library) and its metadata.",
|
||||
"distribution": 5,
|
||||
"distribution": "5",
|
||||
"meta-category": "network",
|
||||
"name": "url",
|
||||
"sharing_group_id": 0,
|
||||
"sharing_group_id": "0",
|
||||
"template_uuid": "60efb77b-40b5-4c46-871b-ed1ed999fce5",
|
||||
"template_version": 6,
|
||||
"template_version": "6",
|
||||
"uuid": "b"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
}
|
||||
],
|
||||
"description": "File object describing a file with meta-information",
|
||||
"distribution": 5,
|
||||
"distribution": "5",
|
||||
"meta-category": "file",
|
||||
"name": "file",
|
||||
"sharing_group_id": 0,
|
||||
"sharing_group_id": "0",
|
||||
"template_uuid": "688c46fb-5edb-40a3-8273-1af7923e2215",
|
||||
"template_version": 13,
|
||||
"template_version": "13",
|
||||
"uuid": "a"
|
||||
},
|
||||
{
|
||||
|
@ -43,12 +43,12 @@
|
|||
}
|
||||
],
|
||||
"description": "File object describing a file with meta-information",
|
||||
"distribution": 5,
|
||||
"distribution": "5",
|
||||
"meta-category": "file",
|
||||
"name": "file",
|
||||
"sharing_group_id": 0,
|
||||
"sharing_group_id": "0",
|
||||
"template_uuid": "688c46fb-5edb-40a3-8273-1af7923e2215",
|
||||
"template_version": 13,
|
||||
"template_version": "13",
|
||||
"uuid": "b"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -21,13 +21,13 @@
|
|||
}
|
||||
],
|
||||
"description": "TestTemplate.",
|
||||
"distribution": 5,
|
||||
"distribution": "5",
|
||||
"meta-category": "file",
|
||||
"misp_objects_path_custom": "tests/mispevent_testfiles",
|
||||
"name": "test_object_template",
|
||||
"sharing_group_id": 0,
|
||||
"sharing_group_id": "0",
|
||||
"template_uuid": "4ec55cc6-9e49-4c64-b794-03c25c1a6589",
|
||||
"template_version": 1,
|
||||
"template_version": "1",
|
||||
"uuid": "a"
|
||||
}
|
||||
],
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"timestamp": 11111111,
|
||||
"timestamp": "11111111",
|
||||
"type": "bar",
|
||||
"value": "1"
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
"misp-attribute": "text"
|
||||
}
|
||||
},
|
||||
"version": 1,
|
||||
"version": "1",
|
||||
"description": "TestTemplate.",
|
||||
"meta-category": "file",
|
||||
"uuid": "4ec55cc6-9e49-4c64-b794-03c25c1a6589",
|
||||
|
|
Loading…
Reference in New Issue