Skip to content

Commit

Permalink
added MetaObject
Browse files Browse the repository at this point in the history
  • Loading branch information
rpiazza committed Mar 27, 2024
1 parent 9a1663f commit 5f23033
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 10 deletions.
4 changes: 4 additions & 0 deletions stix2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ def _check_object_constraints(self):
self._check_at_least_one_property()


class _MetaObject(_STIXBase):
pass


def _choose_one_hash(hash_dict):
if "MD5" in hash_dict:
return {"MD5": hash_dict["MD5"]}
Expand Down
1 change: 1 addition & 0 deletions stix2/datastore/relational_db/input_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from sqlalchemy import insert

from stix2.datastore.relational_db.add_method import add_method
from stix2.datastore.relational_db.utils import (
SCO_COMMON_PROPERTIES, SDO_COMMON_PROPERTIES, canonicalize_table_name,
)
Expand Down
4 changes: 3 additions & 1 deletion stix2/datastore/relational_db/relational_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from stix2.datastore.relational_db.utils import canonicalize_table_name
from stix2.parsing import parse
from stix2.v21.base import (
_DomainObject, _Extension, _Observable, _RelationshipObject,
_DomainObject, _Extension, _MetaObject, _Observable, _RelationshipObject,
)


Expand Down Expand Up @@ -158,6 +158,8 @@ def _create_table_objects(self):
tables.extend(new_tables)
for stix_class in _get_all_subclasses(_Observable):
tables.extend(generate_object_table(stix_class, self.metadata, "sco"))
for stix_class in _get_all_subclasses(_MetaObject):
tables.extend(generate_object_table(stix_class, self.metadata, "common"))
for stix_class in _get_all_subclasses(_Extension):
if stix_class.extension_type not in ["new-sdo", "new-sco", "new-sro"]:
if hasattr(stix_class, "_applies_to"):
Expand Down
2 changes: 1 addition & 1 deletion stix2/datastore/relational_db/table_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def generate_table_information(self, name, metadata, schema_name, table_name, **
ForeignKey(
canonicalize_table_name(table_name, schema_name) + ".id",
ondelete="CASCADE",
)
),
),
)
columns.append(
Expand Down
7 changes: 6 additions & 1 deletion stix2/v20/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Base classes for STIX 2.0 type definitions."""

from ..base import (
_DomainObject, _Extension, _Observable, _RelationshipObject, _STIXBase,
_DomainObject, _Extension, _MetaObject, _Observable, _RelationshipObject,
_STIXBase,
)


Expand All @@ -23,3 +24,7 @@ class _DomainObject(_DomainObject, _STIXBase20):

class _RelationshipObject(_RelationshipObject, _STIXBase20):
pass


class _MetaObject(_MetaObject, _STIXBase20):
pass
4 changes: 2 additions & 2 deletions stix2/v20/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
SelectorProperty, StringProperty, TimestampProperty, TypeProperty,
)
from ..utils import NOW, _get_dict
from .base import _STIXBase20
from .base import _MetaObject, _STIXBase20
from .vocab import HASHING_ALGORITHM


Expand Down Expand Up @@ -111,7 +111,7 @@ def clean(self, value, allow_custom=False):
raise ValueError("must be a Statement, TLP Marking or a registered marking.")


class MarkingDefinition(_STIXBase20, _MarkingsMixin):
class MarkingDefinition(_MetaObject, _MarkingsMixin):
"""For more detailed information on this object's properties, see
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part1-stix-core/stix-v2.0-cs01-part1-stix-core.html#_Toc496709284>`__.
"""
Expand Down
7 changes: 6 additions & 1 deletion stix2/v21/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Base classes for STIX 2.1 type definitions."""

from ..base import (
_DomainObject, _Extension, _Observable, _RelationshipObject, _STIXBase,
_DomainObject, _Extension, _MetaObject, _Observable, _RelationshipObject,
_STIXBase,
)


Expand Down Expand Up @@ -40,3 +41,7 @@ class _DomainObject(_DomainObject, _STIXBase21):

class _RelationshipObject(_RelationshipObject, _STIXBase21):
pass


class _MetaObject(_MetaObject, _STIXBase21):
pass
8 changes: 4 additions & 4 deletions stix2/v21/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
TypeProperty,
)
from ..utils import NOW, _get_dict
from .base import _STIXBase21
from .base import _MetaObject, _STIXBase21
from .vocab import EXTENSION_TYPE, HASHING_ALGORITHM


Expand Down Expand Up @@ -79,7 +79,7 @@ def _check_object_constraints(self):
self._check_at_least_one_property(['lang', 'marking_ref'])


class LanguageContent(_STIXBase21):
class LanguageContent(_MetaObject):
"""For more detailed information on this object's properties, see
`the STIX 2.1 specification <https://docs.oasis-open.org/cti/stix/v2.1/os/stix-v2.1-os.html#_z9r1cwtu8jja>`__.
"""
Expand Down Expand Up @@ -107,7 +107,7 @@ class LanguageContent(_STIXBase21):
])


class ExtensionDefinition(_STIXBase21):
class ExtensionDefinition(_MetaObject):
"""For more detailed information on this object's properties, see
`the STIX 2.1 specification <https://docs.oasis-open.org/cti/stix/v2.1/os/stix-v2.1-os.html#_32j232tfvtly>`__.
"""
Expand Down Expand Up @@ -190,7 +190,7 @@ def clean(self, value, allow_custom=False):
raise ValueError("must be a Statement, TLP Marking or a registered marking.")


class MarkingDefinition(_STIXBase21, _MarkingsMixin):
class MarkingDefinition(_MetaObject, _MarkingsMixin):
"""For more detailed information on this object's properties, see
`the STIX 2.1 specification <https://docs.oasis-open.org/cti/stix/v2.1/os/stix-v2.1-os.html#_k5fndj2c7c1k>`__.
"""
Expand Down

0 comments on commit 5f23033

Please sign in to comment.