Change SROs to OrderedDict approach. Removed COMMON_PROPERTIES.
parent
8086447fce
commit
dd2a1db5c1
75
stix2/sro.py
75
stix2/sro.py
|
@ -1,31 +1,39 @@
|
||||||
"""STIX 2.0 Relationship Objects."""
|
"""STIX 2.0 Relationship Objects."""
|
||||||
|
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
from .base import _STIXBase
|
from .base import _STIXBase
|
||||||
from .common import COMMON_PROPERTIES
|
from .other import ExternalReference, GranularMarking
|
||||||
from .properties import (IDProperty, IntegerProperty, ListProperty,
|
from .properties import (BooleanProperty, IDProperty, IntegerProperty, ListProperty,
|
||||||
ReferenceProperty, StringProperty, TimestampProperty,
|
ReferenceProperty, StringProperty, TimestampProperty,
|
||||||
TypeProperty)
|
TypeProperty)
|
||||||
|
from .utils import NOW
|
||||||
|
|
||||||
|
|
||||||
class Relationship(_STIXBase):
|
class Relationship(_STIXBase):
|
||||||
|
|
||||||
_type = 'relationship'
|
_type = 'relationship'
|
||||||
_properties = COMMON_PROPERTIES.copy()
|
_properties = OrderedDict()
|
||||||
_properties.update({
|
_properties.update([
|
||||||
'id': IDProperty(_type),
|
('type', TypeProperty(_type)),
|
||||||
'type': TypeProperty(_type),
|
('id', IDProperty(_type)),
|
||||||
'relationship_type': StringProperty(required=True),
|
('created_by_ref', ReferenceProperty(type="identity")),
|
||||||
'description': StringProperty(),
|
('created', TimestampProperty(default=lambda: NOW, precision='millisecond')),
|
||||||
'source_ref': ReferenceProperty(required=True),
|
('modified', TimestampProperty(default=lambda: NOW, precision='millisecond')),
|
||||||
'target_ref': ReferenceProperty(required=True),
|
('relationship_type', StringProperty(required=True)),
|
||||||
})
|
('description', StringProperty()),
|
||||||
|
('source_ref', ReferenceProperty(required=True)),
|
||||||
|
('target_ref', ReferenceProperty(required=True)),
|
||||||
|
('revoked', BooleanProperty()),
|
||||||
|
('labels', ListProperty(StringProperty)),
|
||||||
|
('external_references', ListProperty(ExternalReference)),
|
||||||
|
('object_marking_refs', ListProperty(ReferenceProperty(type="marking-definition"))),
|
||||||
|
('granular_markings', ListProperty(GranularMarking)),
|
||||||
|
])
|
||||||
|
|
||||||
# Explicitly define the first three kwargs to make readable Relationship declarations.
|
# Explicitly define the first three kwargs to make readable Relationship declarations.
|
||||||
def __init__(self, source_ref=None, relationship_type=None, target_ref=None,
|
def __init__(self, source_ref=None, relationship_type=None,
|
||||||
**kwargs):
|
target_ref=None, **kwargs):
|
||||||
# TODO:
|
|
||||||
# - description
|
|
||||||
|
|
||||||
# Allow (source_ref, relationship_type, target_ref) as positional args.
|
# Allow (source_ref, relationship_type, target_ref) as positional args.
|
||||||
if source_ref and not kwargs.get('source_ref'):
|
if source_ref and not kwargs.get('source_ref'):
|
||||||
kwargs['source_ref'] = source_ref
|
kwargs['source_ref'] = source_ref
|
||||||
|
@ -39,24 +47,29 @@ class Relationship(_STIXBase):
|
||||||
|
|
||||||
class Sighting(_STIXBase):
|
class Sighting(_STIXBase):
|
||||||
_type = 'sighting'
|
_type = 'sighting'
|
||||||
_properties = COMMON_PROPERTIES.copy()
|
_properties = OrderedDict()
|
||||||
_properties.update({
|
_properties.update([
|
||||||
'id': IDProperty(_type),
|
('id', IDProperty(_type)),
|
||||||
'type': TypeProperty(_type),
|
('type', TypeProperty(_type)),
|
||||||
'first_seen': TimestampProperty(),
|
('created_by_ref', ReferenceProperty(type="identity")),
|
||||||
'last_seen': TimestampProperty(),
|
('created', TimestampProperty(default=lambda: NOW, precision='millisecond')),
|
||||||
'count': IntegerProperty(),
|
('modified', TimestampProperty(default=lambda: NOW, precision='millisecond')),
|
||||||
'sighting_of_ref': ReferenceProperty(required=True),
|
('first_seen', TimestampProperty()),
|
||||||
'observed_data_refs': ListProperty(ReferenceProperty(type="observed-data")),
|
('last_seen', TimestampProperty()),
|
||||||
'where_sighted_refs': ListProperty(ReferenceProperty(type="identity")),
|
('count', IntegerProperty()),
|
||||||
'summary': StringProperty(),
|
('sighting_of_ref', ReferenceProperty(required=True)),
|
||||||
})
|
('observed_data_refs', ListProperty(ReferenceProperty(type="observed-data"))),
|
||||||
|
('where_sighted_refs', ListProperty(ReferenceProperty(type="identity"))),
|
||||||
|
('summary', BooleanProperty()),
|
||||||
|
('revoked', BooleanProperty()),
|
||||||
|
('labels', ListProperty(StringProperty)),
|
||||||
|
('external_references', ListProperty(ExternalReference)),
|
||||||
|
('object_marking_refs', ListProperty(ReferenceProperty(type="marking-definition"))),
|
||||||
|
('granular_markings', ListProperty(GranularMarking)),
|
||||||
|
])
|
||||||
|
|
||||||
# Explicitly define the first kwargs to make readable Sighting declarations.
|
# Explicitly define the first kwargs to make readable Sighting declarations.
|
||||||
def __init__(self, sighting_of_ref=None, **kwargs):
|
def __init__(self, sighting_of_ref=None, **kwargs):
|
||||||
# TODO:
|
|
||||||
# - description
|
|
||||||
|
|
||||||
# Allow sighting_of_ref as a positional arg.
|
# Allow sighting_of_ref as a positional arg.
|
||||||
if sighting_of_ref and not kwargs.get('sighting_of_ref'):
|
if sighting_of_ref and not kwargs.get('sighting_of_ref'):
|
||||||
kwargs['sighting_of_ref'] = sighting_of_ref
|
kwargs['sighting_of_ref'] = sighting_of_ref
|
||||||
|
|
Loading…
Reference in New Issue