Add get_obj function to bundle.py to make accessing bundles easier

master
Desai, Kartikey H 2019-05-14 13:48:54 -04:00
parent 67f6663e5e
commit a61344a8aa
2 changed files with 5 additions and 0 deletions

View File

@ -183,6 +183,8 @@ def test_parse_bundle(version):
assert bundle.objects[0].type == 'indicator'
assert bundle.objects[1].type == 'malware'
assert bundle.objects[2].type == 'relationship'
assert bundle.get_obj('malware--00000000-0000-4000-8000-000000000003').type == 'malware'
assert bundle.get_obj('blah blah') is None
def test_parse_unknown_type():

View File

@ -33,3 +33,6 @@ class Bundle(_STIXBase):
self._properties['objects'].contained.allow_custom = kwargs.get('allow_custom', False)
super(Bundle, self).__init__(**kwargs)
def get_obj(self, obj_uuid):
return next((elem for elem in self.objects if elem['id'] == obj_uuid), None)