2020-03-22 03:22:36 +01:00
|
|
|
"""Base classes for STIX 2.1 type definitions."""
|
|
|
|
|
2020-03-27 07:40:42 +01:00
|
|
|
from ..base import (
|
|
|
|
_DomainObject, _Extension, _Observable, _RelationshipObject, _STIXBase,
|
|
|
|
)
|
2020-03-22 03:22:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
class _STIXBase21(_STIXBase):
|
2020-10-20 04:18:45 +02:00
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
if 'extensions' in self._properties:
|
|
|
|
self._properties['extensions'].allow_custom = kwargs.get('allow_custom', False)
|
|
|
|
super(_STIXBase21, self).__init__(**kwargs)
|
2020-03-22 03:22:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
class _Observable(_Observable, _STIXBase21):
|
2020-11-11 00:32:58 +01:00
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super(_Observable, self).__init__(**kwargs)
|
|
|
|
if 'id' not in kwargs:
|
|
|
|
# Specific to 2.1+ observables: generate a deterministic ID
|
|
|
|
id_ = self._generate_id()
|
|
|
|
|
|
|
|
# Spec says fall back to UUIDv4 if no contributing properties were
|
|
|
|
# given. That's what already happened (the following is actually
|
|
|
|
# overwriting the default uuidv4), so nothing to do here.
|
|
|
|
if id_ is not None:
|
|
|
|
# Can't assign to self (we're immutable), so slip the ID in
|
|
|
|
# more sneakily.
|
|
|
|
self._inner["id"] = id_
|
2020-03-22 03:22:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
class _Extension(_Extension, _STIXBase21):
|
2020-12-23 03:41:46 +01:00
|
|
|
extension_type = None
|
2020-11-11 00:32:58 +01:00
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super(_Extension, self).__init__(**kwargs)
|
2020-12-23 03:41:46 +01:00
|
|
|
if getattr(self, "extension_type", None):
|
|
|
|
self._inner["extension_type"] = self.extension_type
|
2020-11-11 00:32:58 +01:00
|
|
|
|
|
|
|
def _check_at_least_one_property(self, list_of_properties=None):
|
2020-12-23 03:41:46 +01:00
|
|
|
new_ext_check = getattr(self, "extension_type", None)
|
2020-11-11 00:32:58 +01:00
|
|
|
|
2020-12-23 03:41:46 +01:00
|
|
|
if new_ext_check is None:
|
2020-11-11 00:32:58 +01:00
|
|
|
super(_Extension, self)._check_at_least_one_property(list_of_properties=list_of_properties)
|
2020-03-22 03:22:36 +01:00
|
|
|
|
|
|
|
|
2020-03-27 07:40:42 +01:00
|
|
|
class _DomainObject(_DomainObject, _STIXBase21):
|
2020-03-22 03:22:36 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2020-03-27 07:40:42 +01:00
|
|
|
class _RelationshipObject(_RelationshipObject, _STIXBase21):
|
2020-03-22 03:22:36 +01:00
|
|
|
pass
|