mirror of https://github.com/MISP/PyMISP
We can now upload stix object directly. File is not necessary.
parent
7e84c36406
commit
115bc59425
|
@ -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 isinstance(path, (str, Path)):
|
if path is not None:
|
||||||
with open(path, 'rb') as f:
|
if isinstance(path, (str, Path)):
|
||||||
to_post = f.read()
|
with open(path, 'rb') as f:
|
||||||
|
to_post = f.read()
|
||||||
|
else:
|
||||||
|
to_post = path.read()
|
||||||
|
elif data is not None:
|
||||||
|
to_post = data
|
||||||
else:
|
else:
|
||||||
to_post = path.read()
|
raise MISPServerError("please fill path or data parameter")
|
||||||
|
|
||||||
if isinstance(to_post, bytes):
|
|
||||||
to_post = to_post.decode() # type: ignore
|
|
||||||
|
|
||||||
if str(version) == '1':
|
if str(version) == '1':
|
||||||
url = urljoin(self.root_url, '/events/upload_stix')
|
url = urljoin(self.root_url, '/events/upload_stix')
|
||||||
|
|
Loading…
Reference in New Issue