new: get_objects_by_name in MISPEvent

new: Convert datetime objects to python datetime.
pull/426/head
Raphaël Vinot 2019-07-23 16:37:26 +02:00
parent 457bbca839
commit 5a3e3def97
2 changed files with 11 additions and 1 deletions

@ -1 +1 @@
Subproject commit ab9c1e4cd666c12acd2ad09b239e3a826cb382ab
Subproject commit 56506646658688ee32227fd3ef086c9373f59809

View File

@ -195,6 +195,8 @@ class MISPAttribute(AbstractMISP):
self.value = kwargs.pop('value', None)
if self.value is None:
raise NewAttributeError('The value of the attribute is required.')
if self.type == 'datetime' and isinstance(self.value, str):
self.value = parse(self.value)
# Default values
self.category = kwargs.pop('category', type_defaults['default_category'])
@ -695,6 +697,14 @@ class MISPEvent(AbstractMISP):
return obj
raise InvalidMISPObject('Object with {} does not exist in this event'.format(object_uuid))
def get_objects_by_name(self, object_name):
"""Get an object by UUID (UUID is set by the server when creating the new object)"""
objects = []
for obj in self.objects:
if hasattr(obj, 'uuid') and obj.name == object_name:
objects.append(obj)
return objects
def add_object(self, obj=None, **kwargs):
"""Add an object to the Event, either by passing a MISPObject, or a dictionary"""
if isinstance(obj, MISPObject):