mirror of https://github.com/MISP/PyMISP
API made a bit more flexible with input data
- input for add_event() and update_event() can now be a JSON object, JSON string, XMLpull/2/merge
parent
c315ecaef6
commit
507c5a5446
|
@ -4,7 +4,6 @@
|
|||
import sys
|
||||
|
||||
from pymisp import PyMISP
|
||||
import json
|
||||
|
||||
from keys import cert, priv
|
||||
|
||||
|
@ -31,7 +30,7 @@ def init(cert_to_priv=True):
|
|||
def _to_utf8(request):
|
||||
to_return = None
|
||||
if 'json' in request.headers['content-type']:
|
||||
to_return = json.dumps(request.json())
|
||||
to_return = request.json()
|
||||
else:
|
||||
to_return = request.text.encode('utf-8')
|
||||
return to_return
|
||||
|
|
|
@ -81,9 +81,15 @@ class PyMISP(object):
|
|||
"""
|
||||
Add a new event
|
||||
|
||||
:param event: Event object to add
|
||||
:param event: Event as JSON object / string or XML to add
|
||||
"""
|
||||
session = self.__prepare_session()
|
||||
if self.out_type == 'json':
|
||||
if isinstance(event, basestring):
|
||||
return session.post(self.url, data=event)
|
||||
else:
|
||||
return session.post(self.url, data=json.dumps(event))
|
||||
else:
|
||||
return session.post(self.url, data=event)
|
||||
|
||||
def update_event(self, event_id, event):
|
||||
|
@ -91,9 +97,15 @@ class PyMISP(object):
|
|||
Update an event
|
||||
|
||||
:param event_id: Event id to update
|
||||
:param event: Elements to add
|
||||
:param event: Event as JSON object / string or XML to add
|
||||
"""
|
||||
session = self.__prepare_session()
|
||||
if self.out_type == 'json':
|
||||
if isinstance(event, basestring):
|
||||
return session.post(self.rest.format(event_id), data=event)
|
||||
else:
|
||||
return session.post(self.rest.format(event_id), data=json.dumps(event))
|
||||
else:
|
||||
return session.post(self.rest.format(event_id), data=event)
|
||||
|
||||
def delete_event(self, event_id):
|
||||
|
|
Loading…
Reference in New Issue