We can now upload stix object directly. File is not necessary.

pull/653/head
Remy Dewailly 2020-11-03 13:13:32 +01:00
parent 7e84c36406
commit 115bc59425
1 changed files with 11 additions and 8 deletions

View File

@ -2523,20 +2523,23 @@ class PyMISP:
to_return.append(a) to_return.append(a)
return to_return return to_return
def upload_stix(self, path, version: str = '2'): def upload_stix(self, path = None, data = None, version: str = '2'):
"""Upload a STIX file to MISP. """Upload a STIX file to MISP.
:param path: Path to the STIX on the disk (can be a path-like object, or a pseudofile) :param path: Path to the STIX on the disk (can be a path-like object, or a pseudofile)
:param data: stix object
:param version: Can be 1 or 2 :param version: Can be 1 or 2
""" """
if path is not None:
if isinstance(path, (str, Path)): if isinstance(path, (str, Path)):
with open(path, 'rb') as f: with open(path, 'rb') as f:
to_post = f.read() to_post = f.read()
else: else:
to_post = path.read() to_post = path.read()
elif data is not None:
if isinstance(to_post, bytes): to_post = data
to_post = to_post.decode() # type: ignore else:
raise MISPServerError("please fill path or data parameter")
if str(version) == '1': if str(version) == '1':
url = urljoin(self.root_url, '/events/upload_stix') url = urljoin(self.root_url, '/events/upload_stix')