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)
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.
: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
"""
if isinstance(path, (str, Path)):
with open(path, 'rb') as f:
to_post = f.read()
if path is not None:
if isinstance(path, (str, Path)):
with open(path, 'rb') as f:
to_post = f.read()
else:
to_post = path.read()
elif data is not None:
to_post = data
else:
to_post = path.read()
if isinstance(to_post, bytes):
to_post = to_post.decode() # type: ignore
raise MISPServerError("please fill path or data parameter")
if str(version) == '1':
url = urljoin(self.root_url, '/events/upload_stix')