Simplfy MISPEvent.add_attribute

pull/98/head
Raphaël Vinot 2017-07-12 11:08:58 +02:00
parent bb9642445a
commit f64f42ac71
1 changed files with 9 additions and 5 deletions

View File

@ -593,11 +593,15 @@ class MISPEvent(object):
if not found:
raise Exception('No attribute with UUID/ID {} found.'.format(attribute_id))
def add_attribute(self, type_, value, **kwargs):
def add_attribute(self, **kwargs):
if not kwargs.get('value'):
raise NewAttributeError('The value of the attribute is required.')
if not kwargs.get('type'):
raise NewAttributeError('The type of the attribute is required.')
attribute = MISPAttribute(self.describe_types)
if isinstance(value, list):
for a in value:
self.add_attribute(type_, a, **kwargs)
if isinstance(kwargs.get('value'), list):
for a in kwargs.get('value'):
self.add_attribute(kwargs.get('type'), a, **kwargs)
else:
attribute.set_all_values(type=type_, value=value, **kwargs)
attribute.set_all_values(type=kwargs.get('type'), value=kwargs.get('value'), **kwargs)
self.attributes.append(attribute)