modify main codebase based on 7.3 Extension changes
parent
33a472d8f5
commit
4127ea9afd
|
@ -128,7 +128,7 @@ class _STIXBase(Mapping):
|
|||
|
||||
extra_kwargs = list(set(kwargs) - set(self._properties))
|
||||
if extra_kwargs and issubclass(cls, stix2.v21._Extension):
|
||||
props_to_remove = ['extends_stix_object_definition', 'is_new_object', 'is_extension_so']
|
||||
props_to_remove = ['extension_type']
|
||||
extra_kwargs = [prop for prop in extra_kwargs if prop not in props_to_remove]
|
||||
|
||||
if extra_kwargs and not self._allow_custom:
|
||||
|
@ -166,9 +166,7 @@ class _STIXBase(Mapping):
|
|||
missing_kwargs = required_properties - set(setting_kwargs)
|
||||
if missing_kwargs:
|
||||
new_ext_check = (
|
||||
getattr(self, 'extends_stix_object_definition', False) or
|
||||
getattr(self, 'is_new_object', False) or
|
||||
getattr(self, 'is_extension_so', False)
|
||||
bool(getattr(self, "extension_type", None))
|
||||
) and issubclass(cls, stix2.v21._Extension)
|
||||
if new_ext_check is False:
|
||||
raise MissingPropertiesError(cls, missing_kwargs)
|
||||
|
|
|
@ -144,9 +144,7 @@ def dict_to_stix2(stix_dict, allow_custom=False, version=None):
|
|||
# be parsed into STIX object, returned as is
|
||||
return stix_dict
|
||||
for key_id, ext_def in stix_dict.get('extensions', {}).items():
|
||||
if key_id.startswith('stix-extension--') and (
|
||||
ext_def.get('is_new_object', False) or ext_def.get('is_extension_so', False)
|
||||
):
|
||||
if key_id.startswith('stix-extension--') and ext_def.get('extension_type', None):
|
||||
# prevents ParseError for unregistered objects when
|
||||
# 'is_new_object' or 'is_extension_so' are set to True and allow_custom=False
|
||||
return stix_dict
|
||||
|
|
|
@ -31,25 +31,17 @@ class _Observable(_Observable, _STIXBase21):
|
|||
|
||||
|
||||
class _Extension(_Extension, _STIXBase21):
|
||||
extends_stix_object_definition = False
|
||||
is_new_object = False
|
||||
is_extension_so = False
|
||||
extension_type = None
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(_Extension, self).__init__(**kwargs)
|
||||
if getattr(self, "extends_stix_object_definition", False):
|
||||
self._inner["extends_stix_object_definition"] = True
|
||||
elif getattr(self, "is_new_object", False):
|
||||
self._inner["is_new_object"] = True
|
||||
elif getattr(self, "is_extension_so", False):
|
||||
self._inner["is_extension_so"] = True
|
||||
if getattr(self, "extension_type", None):
|
||||
self._inner["extension_type"] = self.extension_type
|
||||
|
||||
def _check_at_least_one_property(self, list_of_properties=None):
|
||||
new_ext_check = (getattr(self, "extends_stix_object_definition", False) or
|
||||
getattr(self, "is_new_object", False) or
|
||||
getattr(self, "is_extension_so", False))
|
||||
new_ext_check = getattr(self, "extension_type", None)
|
||||
|
||||
if new_ext_check is False:
|
||||
if new_ext_check is None:
|
||||
super(_Extension, self)._check_at_least_one_property(list_of_properties=list_of_properties)
|
||||
|
||||
|
||||
|
|
|
@ -255,8 +255,7 @@ def CustomMarking(type='x-custom-marking', properties=None, extension_name=None)
|
|||
|
||||
@observables.CustomExtension(type=extension_name, properties=properties)
|
||||
class NameExtension:
|
||||
# might not be correct
|
||||
extends_stix_object_definition = True
|
||||
extension_type = 'property-extension'
|
||||
|
||||
extension = extension_name.split('--')[1]
|
||||
extension = extension.replace('-', '')
|
||||
|
|
|
@ -945,7 +945,7 @@ def CustomObservable(type='x-custom-observable', properties=None, id_contrib_pro
|
|||
if extension_name:
|
||||
@CustomExtension(type=extension_name, properties=properties)
|
||||
class NameExtension:
|
||||
is_extension_so = True
|
||||
extension_type = 'new-sco'
|
||||
|
||||
extension = extension_name.split('--')[1]
|
||||
extension = extension.replace('-', '')
|
||||
|
|
|
@ -862,7 +862,7 @@ def CustomObject(type='x-custom-type', properties=None, extension_name=None):
|
|||
if extension_name:
|
||||
@observables.CustomExtension(type=extension_name, properties=extension_properties)
|
||||
class NameExtension:
|
||||
is_new_object = True
|
||||
extension_type = 'new-sdo'
|
||||
|
||||
extension = extension_name.split('--')[1]
|
||||
extension = extension.replace('-', '')
|
||||
|
|
Loading…
Reference in New Issue