mirror of https://github.com/MISP/PyMISP
Change in add_attachment. Allow explicit attachment naming
parent
9dd04f8664
commit
788a7842fa
|
@ -557,23 +557,27 @@ class PyMISP(object):
|
||||||
"""Add filename(s)"""
|
"""Add filename(s)"""
|
||||||
return self.add_named_attribute(event, 'filename', filename, category, to_ids, comment, distribution, proposal, **kwargs)
|
return self.add_named_attribute(event, 'filename', filename, category, to_ids, comment, distribution, proposal, **kwargs)
|
||||||
|
|
||||||
def add_attachment(self, event, attachment, category='Artifacts dropped', to_ids=False, comment=None, distribution=None, proposal=False, **kwargs):
|
def add_attachment(self, event, attachment, category='Artifacts dropped', to_ids=False, comment=None, distribution=None, proposal=False, filename=None, **kwargs):
|
||||||
"""Add an attachment to the MISP event
|
"""Add an attachment to the MISP event
|
||||||
|
|
||||||
:param event: The event to add an attachment to
|
:param event: The event to add an attachment to
|
||||||
:param attachment: Either a file handle or a path to a file - will be uploaded
|
:param attachment: Either a file handle or a path to a file - will be uploaded
|
||||||
|
:param filename: Explicitly defined attachment filename
|
||||||
"""
|
"""
|
||||||
if isinstance(attachment, basestring) and os.path.isfile(attachment):
|
if isinstance(attachment, basestring) and os.path.isfile(attachment):
|
||||||
# We have a file to open
|
# We have a file to open
|
||||||
|
if filename = None:
|
||||||
filename = os.path.basename(attachment)
|
filename = os.path.basename(attachment)
|
||||||
with open(attachment, "rb") as f:
|
with open(attachment, "rb") as f:
|
||||||
fileData = f.read()
|
fileData = f.read()
|
||||||
elif hasattr(attachment, "read"):
|
elif hasattr(attachment, "read"):
|
||||||
# It's a file handle - we can read it but it has no filename
|
# It's a file handle - we can read it but it has no filename
|
||||||
fileData = attachment.read()
|
fileData = attachment.read()
|
||||||
|
if filename = None:
|
||||||
filename = 'attachment'
|
filename = 'attachment'
|
||||||
elif isinstance(attachment, (tuple, list)):
|
elif isinstance(attachment, (tuple, list)):
|
||||||
# tuple/list (filename, pseudofile)
|
# tuple/list (filename, pseudofile)
|
||||||
|
if filename = None:
|
||||||
filename = attachment[0]
|
filename = attachment[0]
|
||||||
if hasattr(attachment[1], "read"):
|
if hasattr(attachment[1], "read"):
|
||||||
# Pseudo file
|
# Pseudo file
|
||||||
|
@ -582,6 +586,7 @@ class PyMISP(object):
|
||||||
fileData = attachment[1]
|
fileData = attachment[1]
|
||||||
else:
|
else:
|
||||||
# Plain file content, no filename
|
# Plain file content, no filename
|
||||||
|
if filename = None:
|
||||||
filename = 'attachment'
|
filename = 'attachment'
|
||||||
fileData = attachment
|
fileData = attachment
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue