Move the CustomExtension decorator from the v21.observables module
to v21.common. Custom extensions are not specific to SCOs, so I don't know why it was in that module. Now, ExtensionDefinition and CustomExtension are together in the same module, just like MarkingDefinition and CustomMarking are together. Made sense to me.pull/1/head
parent
6fc39a70ea
commit
b9eba77008
|
@ -19,13 +19,13 @@ from .base import (
|
|||
)
|
||||
from .bundle import Bundle
|
||||
from .common import (
|
||||
TLP_AMBER, TLP_GREEN, TLP_RED, TLP_WHITE, CustomMarking,
|
||||
TLP_AMBER, TLP_GREEN, TLP_RED, TLP_WHITE, CustomExtension, CustomMarking,
|
||||
ExtensionDefinition, ExternalReference, GranularMarking, KillChainPhase,
|
||||
LanguageContent, MarkingDefinition, StatementMarking, TLPMarking,
|
||||
)
|
||||
from .observables import (
|
||||
URL, AlternateDataStream, ArchiveExt, Artifact, AutonomousSystem,
|
||||
CustomExtension, CustomObservable, Directory, DomainName, EmailAddress,
|
||||
CustomObservable, Directory, DomainName, EmailAddress,
|
||||
EmailMessage, EmailMIMEComponent, File, HTTPRequestExt, ICMPExt,
|
||||
IPv4Address, IPv6Address, MACAddress, Mutex, NetworkTraffic, NTFSExt,
|
||||
PDFExt, Process, RasterImageExt, SocketExt, Software, TCPExt,
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
"""STIX 2.1 Common Data Types and Properties."""
|
||||
|
||||
from collections import OrderedDict
|
||||
from collections.abc import Mapping
|
||||
|
||||
from ..custom import _custom_marking_builder
|
||||
from . import _Extension
|
||||
from ..custom import _custom_marking_builder, _custom_extension_builder
|
||||
from ..exceptions import InvalidValueError, PropertyPresenceError
|
||||
from ..markings import _MarkingsMixin
|
||||
from ..markings.utils import check_tlp_marking
|
||||
|
@ -139,6 +141,30 @@ class ExtensionDefinition(_STIXBase21):
|
|||
])
|
||||
|
||||
|
||||
def CustomExtension(type='x-custom-ext', properties=None):
|
||||
"""Custom STIX Object Extension decorator.
|
||||
"""
|
||||
def wrapper(cls):
|
||||
|
||||
# Auto-create an "extension_type" property from the class attribute, if
|
||||
# it exists.
|
||||
extension_type = getattr(cls, "extension_type", None)
|
||||
if extension_type:
|
||||
extension_type_prop = EnumProperty(
|
||||
EXTENSION_TYPE,
|
||||
required=False,
|
||||
fixed=extension_type,
|
||||
)
|
||||
|
||||
if isinstance(properties, Mapping):
|
||||
properties["extension_type"] = extension_type_prop
|
||||
else:
|
||||
properties.append(("extension_type", extension_type_prop))
|
||||
|
||||
return _custom_extension_builder(cls, type, properties, '2.1', _Extension)
|
||||
return wrapper
|
||||
|
||||
|
||||
class TLPMarking(_STIXBase21):
|
||||
"""For more detailed information on this object's properties, see
|
||||
`the STIX 2.1 specification <https://docs.oasis-open.org/cti/stix/v2.1/cs02/stix-v2.1-cs02.html#_yd3ar14ekwrs>`__.
|
||||
|
@ -260,7 +286,7 @@ def CustomMarking(type='x-custom-marking', properties=None, extension_name=None)
|
|||
if extension_name:
|
||||
from . import observables
|
||||
|
||||
@observables.CustomExtension(type=extension_name, properties=properties)
|
||||
@CustomExtension(type=extension_name, properties=properties)
|
||||
class NameExtension:
|
||||
extension_type = 'property-extension'
|
||||
|
||||
|
|
|
@ -6,10 +6,9 @@ _Observable and do not have a ``_type`` attribute.
|
|||
"""
|
||||
|
||||
from collections import OrderedDict
|
||||
from collections.abc import Mapping
|
||||
import itertools
|
||||
|
||||
from ..custom import _custom_extension_builder, _custom_observable_builder
|
||||
from ..custom import _custom_observable_builder
|
||||
from ..exceptions import AtLeastOnePropertyError, DependentPropertiesError
|
||||
from ..properties import (
|
||||
BinaryProperty, BooleanProperty, DictionaryProperty,
|
||||
|
@ -19,9 +18,9 @@ from ..properties import (
|
|||
TypeProperty,
|
||||
)
|
||||
from .base import _Extension, _Observable, _STIXBase21
|
||||
from .common import GranularMarking
|
||||
from .common import GranularMarking, CustomExtension
|
||||
from .vocab import (
|
||||
ACCOUNT_TYPE, ENCRYPTION_ALGORITHM, EXTENSION_TYPE, HASHING_ALGORITHM,
|
||||
ACCOUNT_TYPE, ENCRYPTION_ALGORITHM, HASHING_ALGORITHM,
|
||||
NETWORK_SOCKET_ADDRESS_FAMILY, NETWORK_SOCKET_TYPE,
|
||||
WINDOWS_INTEGRITY_LEVEL, WINDOWS_PEBINARY_TYPE, WINDOWS_REGISTRY_DATATYPE,
|
||||
WINDOWS_SERVICE_START_TYPE, WINDOWS_SERVICE_STATUS, WINDOWS_SERVICE_TYPE,
|
||||
|
@ -898,25 +897,3 @@ def CustomObservable(type='x-custom-observable', properties=None, id_contrib_pro
|
|||
return wrapper
|
||||
|
||||
|
||||
def CustomExtension(type='x-custom-observable-ext', properties=None):
|
||||
"""Custom STIX Object Extension decorator.
|
||||
"""
|
||||
def wrapper(cls):
|
||||
|
||||
# Auto-create an "extension_type" property from the class attribute, if
|
||||
# it exists.
|
||||
extension_type = getattr(cls, "extension_type", None)
|
||||
if extension_type:
|
||||
extension_type_prop = EnumProperty(
|
||||
EXTENSION_TYPE,
|
||||
required=False,
|
||||
fixed=extension_type,
|
||||
)
|
||||
|
||||
if isinstance(properties, Mapping):
|
||||
properties["extension_type"] = extension_type_prop
|
||||
else:
|
||||
properties.append(("extension_type", extension_type_prop))
|
||||
|
||||
return _custom_extension_builder(cls, type, properties, '2.1', _Extension)
|
||||
return wrapper
|
||||
|
|
|
@ -7,7 +7,6 @@ import warnings
|
|||
|
||||
from stix2patterns.validator import run_validator
|
||||
|
||||
from . import observables
|
||||
from ..custom import _custom_object_builder
|
||||
from ..exceptions import (
|
||||
InvalidValueError, PropertyPresenceError, STIXDeprecationWarning,
|
||||
|
@ -20,7 +19,9 @@ from ..properties import (
|
|||
)
|
||||
from ..utils import NOW
|
||||
from .base import _DomainObject
|
||||
from .common import ExternalReference, GranularMarking, KillChainPhase
|
||||
from .common import (
|
||||
CustomExtension, ExternalReference, GranularMarking, KillChainPhase
|
||||
)
|
||||
from .vocab import (
|
||||
ATTACK_MOTIVATION, ATTACK_RESOURCE_LEVEL, GROUPING_CONTEXT, IDENTITY_CLASS,
|
||||
IMPLEMENTATION_LANGUAGE, INDICATOR_TYPE, INDUSTRY_SECTOR,
|
||||
|
@ -858,7 +859,7 @@ def CustomObject(type='x-custom-type', properties=None, extension_name=None, is_
|
|||
]),
|
||||
)
|
||||
if extension_name:
|
||||
@observables.CustomExtension(type=extension_name, properties=extension_properties)
|
||||
@CustomExtension(type=extension_name, properties=extension_properties)
|
||||
class NameExtension:
|
||||
if is_sdo:
|
||||
extension_type = 'new-sdo'
|
||||
|
|
Loading…
Reference in New Issue