Remove registry.get_stix2_class_maps(), since now that the
class map structure is keyed by normal "X.Y" style versions, the convenience that function provided is no longer necessary. So it no longer makes sense to have the function (at least, not for that reason). Change users of that function to use the STIX2_OBJ_MAPS structure directly.pull/1/head
parent
f88fba6751
commit
db1d0b736b
|
@ -68,9 +68,7 @@ def _register_marking(new_marking, version=DEFAULT_VERSION):
|
||||||
if not re.match(PREFIX_21_REGEX, prop_name):
|
if not re.match(PREFIX_21_REGEX, prop_name):
|
||||||
raise ValueError("Property name '%s' must begin with an alpha character." % prop_name)
|
raise ValueError("Property name '%s' must begin with an alpha character." % prop_name)
|
||||||
|
|
||||||
class_maps = registry.get_stix2_class_maps(version)
|
OBJ_MAP_MARKING = registry.STIX2_OBJ_MAPS[version]['markings']
|
||||||
|
|
||||||
OBJ_MAP_MARKING = class_maps['markings']
|
|
||||||
if mark_type in OBJ_MAP_MARKING.keys():
|
if mark_type in OBJ_MAP_MARKING.keys():
|
||||||
raise DuplicateRegistrationError("STIX Marking", mark_type)
|
raise DuplicateRegistrationError("STIX Marking", mark_type)
|
||||||
OBJ_MAP_MARKING[mark_type] = new_marking
|
OBJ_MAP_MARKING[mark_type] = new_marking
|
||||||
|
@ -129,9 +127,7 @@ def _register_observable(new_observable, version=DEFAULT_VERSION):
|
||||||
"is not a ListProperty containing ReferenceProperty." % prop_name,
|
"is not a ListProperty containing ReferenceProperty." % prop_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
class_maps = registry.get_stix2_class_maps(version)
|
OBJ_MAP_OBSERVABLE = registry.STIX2_OBJ_MAPS[version]['observables']
|
||||||
|
|
||||||
OBJ_MAP_OBSERVABLE = class_maps['observables']
|
|
||||||
if new_observable._type in OBJ_MAP_OBSERVABLE.keys():
|
if new_observable._type in OBJ_MAP_OBSERVABLE.keys():
|
||||||
raise DuplicateRegistrationError("Cyber Observable", new_observable._type)
|
raise DuplicateRegistrationError("Cyber Observable", new_observable._type)
|
||||||
OBJ_MAP_OBSERVABLE[new_observable._type] = new_observable
|
OBJ_MAP_OBSERVABLE[new_observable._type] = new_observable
|
||||||
|
@ -185,9 +181,8 @@ def _register_observable_extension(
|
||||||
"created with the @CustomObservable decorator.",
|
"created with the @CustomObservable decorator.",
|
||||||
)
|
)
|
||||||
|
|
||||||
class_maps = registry.get_stix2_class_maps(version)
|
OBJ_MAP_OBSERVABLE = registry.STIX2_OBJ_MAPS[version]['observables']
|
||||||
OBJ_MAP_OBSERVABLE = class_maps['observables']
|
EXT_MAP = registry.STIX2_OBJ_MAPS[version]['observable-extensions']
|
||||||
EXT_MAP = class_maps['observable-extensions']
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if ext_type in EXT_MAP[observable_type].keys():
|
if ext_type in EXT_MAP[observable_type].keys():
|
||||||
|
|
|
@ -42,17 +42,3 @@ def _collect_stix2_mappings():
|
||||||
ver = _stix_vid_to_version(stix_vid)
|
ver = _stix_vid_to_version(stix_vid)
|
||||||
mod = importlib.import_module(name, str(top_level_module.__name__))
|
mod = importlib.import_module(name, str(top_level_module.__name__))
|
||||||
STIX2_OBJ_MAPS[ver]['markings'] = mod.OBJ_MAP_MARKING
|
STIX2_OBJ_MAPS[ver]['markings'] = mod.OBJ_MAP_MARKING
|
||||||
|
|
||||||
|
|
||||||
def get_stix2_class_maps(stix_version):
|
|
||||||
"""
|
|
||||||
Get the stix2 class mappings for the given STIX version.
|
|
||||||
|
|
||||||
:param stix_version: A STIX version as a string
|
|
||||||
:return: The class mappings. This will be a dict mapping from some general
|
|
||||||
category name, e.g. "object" to another mapping from STIX type
|
|
||||||
to a stix2 class.
|
|
||||||
"""
|
|
||||||
cls_maps = STIX2_OBJ_MAPS[stix_version]
|
|
||||||
|
|
||||||
return cls_maps
|
|
||||||
|
|
|
@ -350,7 +350,7 @@ def is_sdo(value, stix_version=stix2.DEFAULT_VERSION):
|
||||||
:return: True if the type of the given value is an SDO type; False
|
:return: True if the type of the given value is an SDO type; False
|
||||||
if not
|
if not
|
||||||
"""
|
"""
|
||||||
cls_maps = mappings.get_stix2_class_maps(stix_version)
|
cls_maps = mappings.STIX2_OBJ_MAPS[stix_version]
|
||||||
type_ = _stix_type_of(value)
|
type_ = _stix_type_of(value)
|
||||||
result = type_ in cls_maps["objects"] and type_ not in {
|
result = type_ in cls_maps["objects"] and type_ not in {
|
||||||
"relationship", "sighting", "marking-definition", "bundle",
|
"relationship", "sighting", "marking-definition", "bundle",
|
||||||
|
@ -370,7 +370,7 @@ def is_sco(value, stix_version=stix2.DEFAULT_VERSION):
|
||||||
:return: True if the type of the given value is an SCO type; False
|
:return: True if the type of the given value is an SCO type; False
|
||||||
if not
|
if not
|
||||||
"""
|
"""
|
||||||
cls_maps = mappings.get_stix2_class_maps(stix_version)
|
cls_maps = mappings.STIX2_OBJ_MAPS[stix_version]
|
||||||
type_ = _stix_type_of(value)
|
type_ = _stix_type_of(value)
|
||||||
result = type_ in cls_maps["observables"]
|
result = type_ in cls_maps["observables"]
|
||||||
|
|
||||||
|
@ -406,7 +406,7 @@ def is_object(value, stix_version=stix2.DEFAULT_VERSION):
|
||||||
:return: True if the type of the given value is a valid STIX type with
|
:return: True if the type of the given value is a valid STIX type with
|
||||||
respect to the given STIX version; False if not
|
respect to the given STIX version; False if not
|
||||||
"""
|
"""
|
||||||
cls_maps = mappings.get_stix2_class_maps(stix_version)
|
cls_maps = mappings.STIX2_OBJ_MAPS[stix_version]
|
||||||
type_ = _stix_type_of(value)
|
type_ = _stix_type_of(value)
|
||||||
result = type_ in cls_maps["observables"] or type_ in cls_maps["objects"]
|
result = type_ in cls_maps["observables"] or type_ in cls_maps["objects"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue