2018-11-28 22:51:00 +01:00
|
|
|
"""STIX 2.1 Bundle Representation."""
|
|
|
|
|
2018-06-14 02:09:07 +02:00
|
|
|
from collections import OrderedDict
|
|
|
|
|
2018-06-26 18:23:53 +02:00
|
|
|
from ..base import _STIXBase
|
2018-07-13 17:10:05 +02:00
|
|
|
from ..properties import (
|
|
|
|
IDProperty, ListProperty, STIXObjectProperty, TypeProperty,
|
|
|
|
)
|
2018-06-14 02:09:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Bundle(_STIXBase):
|
2018-07-10 21:02:55 +02:00
|
|
|
# TODO: Add link
|
2018-06-14 02:09:07 +02:00
|
|
|
"""For more detailed information on this object's properties, see
|
2018-07-10 21:02:55 +02:00
|
|
|
`the STIX 2.1 specification <link here>`__.
|
2018-06-14 02:09:07 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
_type = 'bundle'
|
2018-06-30 00:38:04 +02:00
|
|
|
_properties = OrderedDict([
|
2018-06-14 02:09:07 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('id', IDProperty(_type)),
|
2018-07-10 21:02:55 +02:00
|
|
|
('objects', ListProperty(STIXObjectProperty(spec_version='2.1'))),
|
2018-06-14 02:09:07 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
# Add any positional arguments to the 'objects' kwarg.
|
|
|
|
if args:
|
|
|
|
if isinstance(args[0], list):
|
|
|
|
kwargs['objects'] = args[0] + list(args[1:]) + kwargs.get('objects', [])
|
|
|
|
else:
|
|
|
|
kwargs['objects'] = list(args) + kwargs.get('objects', [])
|
|
|
|
|
|
|
|
self.__allow_custom = kwargs.get('allow_custom', False)
|
|
|
|
self._properties['objects'].contained.allow_custom = kwargs.get('allow_custom', False)
|
|
|
|
|
|
|
|
super(Bundle, self).__init__(**kwargs)
|
2019-05-14 19:48:54 +02:00
|
|
|
|
|
|
|
def get_obj(self, obj_uuid):
|
|
|
|
return next((elem for elem in self.objects if elem['id'] == obj_uuid), None)
|