Skip to content

Commit

Permalink
Merge pull request MISP#15 from Delta-Sierra/master
Browse files Browse the repository at this point in the history
add comment field in upload_sample
  • Loading branch information
adulau committed Apr 15, 2016
2 parents a231139 + 089b0a7 commit a9aaf69
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pymisp/api.py
Expand Up @@ -583,14 +583,14 @@ def _create_event(self, distribution, threat_level_id, analysis, info):
# Setup details of a new event
if distribution not in [0, 1, 2, 3]:
raise NewEventError('{} is invalid, the distribution has to be in 0, 1, 2, 3'.format(distribution))
if threat_level_id not in [0, 1, 2, 3]:
raise NewEventError('{} is invalid, the threat_level_id has to be in 0, 1, 2, 3'.format(threat_level_id))
if threat_level_id not in [1, 2, 3, 4]:
raise NewEventError('{} is invalid, the threat_level_id has to be in 1, 2, 3, 4'.format(threat_level_id))
if analysis not in [0, 1, 2]:
raise NewEventError('{} is invalid, the analysis has to be in 0, 1, 2'.format(analysis))
return {'distribution': int(distribution), 'info': info,
'threat_level_id': int(threat_level_id), 'analysis': analysis}

def prepare_attribute(self, event_id, distribution, to_ids, category, info,
def prepare_attribute(self, event_id, distribution, to_ids, category, comment, info,
analysis, threat_level_id):
to_post = {'request': {}}
authorized_categs = ['Payload delivery', 'Artifacts dropped', 'Payload installation', 'External analysis', 'Network activity', 'Antivirus detection']
Expand All @@ -614,16 +614,17 @@ def prepare_attribute(self, event_id, distribution, to_ids, category, info,
raise NewAttributeError('{} is invalid, category has to be in {}'.format(category, (', '.join(authorized_categs))))
to_post['request']['category'] = category

to_post['request']['comment'] = comment
return to_post

def _encode_file_to_upload(self, path):
with open(path, 'rb') as f:
return base64.b64encode(f.read())

def upload_sample(self, filename, filepath, event_id, distribution, to_ids,
category, info, analysis, threat_level_id):
category, comment, info, analysis, threat_level_id):
to_post = self.prepare_attribute(event_id, distribution, to_ids, category,
info, analysis, threat_level_id)
comment, info, analysis, threat_level_id)
to_post['request']['files'] = [{'filename': filename, 'data': self._encode_file_to_upload(filepath)}]
return self._upload_sample(to_post)

Expand Down

0 comments on commit a9aaf69

Please sign in to comment.