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)
|
||||
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')
|
||||
|
|
Loading…
Reference in New Issue