WIP: convert bundle to using kwargs.
parent
8843e9b190
commit
b5ab54b6a9
|
@ -80,22 +80,20 @@ class Bundle(_STIXBase):
|
||||||
'objects',
|
'objects',
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, type="bundle", id=None, spec_version="2.0", objects=None):
|
def __init__(self, **kwargs):
|
||||||
id = id or 'bundle--' + str(uuid.uuid4())
|
# TODO: remove once we check all the fields in the right order
|
||||||
if not id.startswith('bundle--'):
|
kwargs = self._check_kwargs(**kwargs)
|
||||||
|
|
||||||
|
if not kwargs.get('id'):
|
||||||
|
kwargs['id'] = 'bundle--' + str(uuid.uuid4())
|
||||||
|
if not kwargs['id'].startswith('bundle--'):
|
||||||
raise ValueError("Bundle id values must begin with 'bundle--'.")
|
raise ValueError("Bundle id values must begin with 'bundle--'.")
|
||||||
|
|
||||||
if spec_version != '2.0':
|
if not kwargs.get('spec_version'):
|
||||||
|
kwargs['spec_version'] = '2.0'
|
||||||
|
if kwargs['spec_version'] != '2.0':
|
||||||
raise ValueError("Bundle must have spec_version='2.0'.")
|
raise ValueError("Bundle must have spec_version='2.0'.")
|
||||||
|
|
||||||
objects = objects or []
|
|
||||||
|
|
||||||
kwargs = {
|
|
||||||
'type': type,
|
|
||||||
'id': id,
|
|
||||||
'spec_version': spec_version,
|
|
||||||
'objects': objects,
|
|
||||||
}
|
|
||||||
super(Bundle, self).__init__(**kwargs)
|
super(Bundle, self).__init__(**kwargs)
|
||||||
|
|
||||||
def _dict(self):
|
def _dict(self):
|
||||||
|
@ -156,12 +154,8 @@ class Indicator(_STIXBase):
|
||||||
raise ValueError("Missing required field for Indicator: 'pattern'.")
|
raise ValueError("Missing required field for Indicator: 'pattern'.")
|
||||||
|
|
||||||
kwargs.update({
|
kwargs.update({
|
||||||
# 'type': kwargs['type'],
|
|
||||||
'id': kwargs['id'],
|
|
||||||
'created': kwargs.get('created', now),
|
'created': kwargs.get('created', now),
|
||||||
'modified': kwargs.get('modified', now),
|
'modified': kwargs.get('modified', now),
|
||||||
'labels': kwargs['labels'],
|
|
||||||
'pattern': kwargs['pattern'],
|
|
||||||
'valid_from': kwargs.get('valid_from', now),
|
'valid_from': kwargs.get('valid_from', now),
|
||||||
})
|
})
|
||||||
super(Indicator, self).__init__(**kwargs)
|
super(Indicator, self).__init__(**kwargs)
|
||||||
|
@ -225,12 +219,8 @@ class Malware(_STIXBase):
|
||||||
raise ValueError("Missing required field for Malware: 'name'.")
|
raise ValueError("Missing required field for Malware: 'name'.")
|
||||||
|
|
||||||
kwargs.update({
|
kwargs.update({
|
||||||
'type': kwargs['type'],
|
|
||||||
'id': kwargs['id'],
|
|
||||||
'created': kwargs.get('created', now),
|
'created': kwargs.get('created', now),
|
||||||
'modified': kwargs.get('modified', now),
|
'modified': kwargs.get('modified', now),
|
||||||
'labels': kwargs['labels'],
|
|
||||||
'name': kwargs['name'],
|
|
||||||
})
|
})
|
||||||
super(Malware, self).__init__(**kwargs)
|
super(Malware, self).__init__(**kwargs)
|
||||||
|
|
||||||
|
@ -308,13 +298,9 @@ class Relationship(_STIXBase):
|
||||||
kwargs['target_ref'] = kwargs['target_ref'].id
|
kwargs['target_ref'] = kwargs['target_ref'].id
|
||||||
|
|
||||||
kwargs.update({
|
kwargs.update({
|
||||||
'type': kwargs['type'],
|
|
||||||
'id': kwargs['id'],
|
|
||||||
'created': kwargs.get('created', now),
|
'created': kwargs.get('created', now),
|
||||||
'modified': kwargs.get('modified', now),
|
'modified': kwargs.get('modified', now),
|
||||||
'relationship_type': kwargs['relationship_type'],
|
'relationship_type': kwargs['relationship_type'],
|
||||||
'source_ref': kwargs['source_ref'],
|
|
||||||
'target_ref': kwargs['target_ref'],
|
|
||||||
})
|
})
|
||||||
super(Relationship, self).__init__(**kwargs)
|
super(Relationship, self).__init__(**kwargs)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue