From 220b7bffff85f810a5e2949e8937238cf408df6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 9 Oct 2018 14:44:07 +0200 Subject: [PATCH] new: direct_call without data means GET --- docs/tutorial/PyMISP_tutorial.ipynb | 24 ++++++++++++++++++++++-- pymisp/api.py | 11 +++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/docs/tutorial/PyMISP_tutorial.ipynb b/docs/tutorial/PyMISP_tutorial.ipynb index e0c7220..0ada011 100644 --- a/docs/tutorial/PyMISP_tutorial.ipynb +++ b/docs/tutorial/PyMISP_tutorial.ipynb @@ -353,7 +353,7 @@ "from pymisp import PyMISP\n", "\n", "misp = PyMISP(misp_url, misp_key, misp_verifycert)\n", - "misp.direct_call('attributes/add/2167', {'type': 'ip-dst', 'value': '8.8.8.8'})\n" + "misp.direct_call('attributes/add/2167', {'type': 'ip-dst', 'value': '8.8.8.8'})" ] }, { @@ -373,7 +373,27 @@ "from pymisp import PyMISP\n", "\n", "misp = PyMISP(misp_url, misp_key, misp_verifycert)\n", - "misp.direct_call('attributes/add/2167', '{\"type\": \"ip-dst\", \"value\": \"8.8.8.9\"}')\n" + "misp.direct_call('attributes/add/2167', '{\"type\": \"ip-dst\", \"value\": \"8.8.8.9\"}')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# The URL of the MISP instance to connect to\n", + "misp_url = 'http://127.0.0.1:8080/'\n", + "# Can be found in the MISP web interface under \n", + "# http://+MISP_URL+/users/view/me -> Authkey\n", + "misp_key = 'fk5BodCZw8owbscW8pQ4ykMASLeJ4NYhuAbshNjo'\n", + "# Should PyMISP verify the MISP certificate\n", + "misp_verifycert = False\n", + "\n", + "from pymisp import PyMISP\n", + "\n", + "misp = PyMISP(misp_url, misp_key, misp_verifycert)\n", + "misp.direct_call('events')" ] }, { diff --git a/pymisp/api.py b/pymisp/api.py index 8088223..4a5f555 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -401,12 +401,15 @@ class PyMISP(object): response = self._prepare_request('POST', url) return self._check_response(response) - def direct_call(self, url, data): + def direct_call(self, url, data=None): '''Very lightweight call that posts a data blob (python dictionary or json string) on the URL''' url = urljoin(self.root_url, url) - if isinstance(data, dict): - data = json.dumps(data) - response = self._prepare_request('POST', url, data) + if not data: + response = self._prepare_request('GET', url) + else: + if isinstance(data, dict): + data = json.dumps(data) + response = self._prepare_request('POST', url, data) return self._check_response(response) # ##############################################