2017-02-10 22:35:02 +01:00
|
|
|
"""STIX 2.0 Relationship Objects."""
|
|
|
|
|
2017-09-01 22:37:49 +02:00
|
|
|
from collections import OrderedDict
|
2017-08-14 14:27:49 +02:00
|
|
|
|
2017-02-10 22:35:02 +01:00
|
|
|
from .base import _STIXBase
|
2017-08-15 14:24:43 +02:00
|
|
|
from .common import ExternalReference, GranularMarking
|
2017-10-06 02:50:54 +02:00
|
|
|
from .markings import _MarkingsMixin
|
2017-08-15 19:54:16 +02:00
|
|
|
from .properties import (BooleanProperty, IDProperty, IntegerProperty,
|
|
|
|
ListProperty, ReferenceProperty, StringProperty,
|
|
|
|
TimestampProperty, TypeProperty)
|
2017-08-14 14:27:49 +02:00
|
|
|
from .utils import NOW
|
2017-02-10 22:35:02 +01:00
|
|
|
|
|
|
|
|
2017-10-06 02:50:54 +02:00
|
|
|
class STIXRelationshipObject(_STIXBase, _MarkingsMixin):
|
2017-10-03 21:01:55 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Relationship(STIXRelationshipObject):
|
2017-02-10 22:35:02 +01:00
|
|
|
|
|
|
|
_type = 'relationship'
|
2017-08-14 14:27:49 +02:00
|
|
|
_properties = OrderedDict()
|
|
|
|
_properties.update([
|
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('id', IDProperty(_type)),
|
|
|
|
('created_by_ref', ReferenceProperty(type="identity")),
|
|
|
|
('created', TimestampProperty(default=lambda: NOW, precision='millisecond')),
|
|
|
|
('modified', TimestampProperty(default=lambda: NOW, precision='millisecond')),
|
|
|
|
('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)),
|
|
|
|
])
|
2017-02-10 22:35:02 +01:00
|
|
|
|
|
|
|
# Explicitly define the first three kwargs to make readable Relationship declarations.
|
2017-08-14 14:27:49 +02:00
|
|
|
def __init__(self, source_ref=None, relationship_type=None,
|
|
|
|
target_ref=None, **kwargs):
|
2017-02-10 22:35:02 +01:00
|
|
|
# Allow (source_ref, relationship_type, target_ref) as positional args.
|
|
|
|
if source_ref and not kwargs.get('source_ref'):
|
|
|
|
kwargs['source_ref'] = source_ref
|
|
|
|
if relationship_type and not kwargs.get('relationship_type'):
|
|
|
|
kwargs['relationship_type'] = relationship_type
|
|
|
|
if target_ref and not kwargs.get('target_ref'):
|
|
|
|
kwargs['target_ref'] = target_ref
|
|
|
|
|
2017-03-31 21:52:27 +02:00
|
|
|
super(Relationship, self).__init__(**kwargs)
|
2017-02-10 22:35:02 +01:00
|
|
|
|
|
|
|
|
2017-10-03 21:01:55 +02:00
|
|
|
class Sighting(STIXRelationshipObject):
|
2017-03-31 21:52:27 +02:00
|
|
|
_type = 'sighting'
|
2017-08-14 14:27:49 +02:00
|
|
|
_properties = OrderedDict()
|
|
|
|
_properties.update([
|
|
|
|
('type', TypeProperty(_type)),
|
2017-08-14 14:31:08 +02:00
|
|
|
('id', IDProperty(_type)),
|
2017-08-14 14:27:49 +02:00
|
|
|
('created_by_ref', ReferenceProperty(type="identity")),
|
|
|
|
('created', TimestampProperty(default=lambda: NOW, precision='millisecond')),
|
|
|
|
('modified', TimestampProperty(default=lambda: NOW, precision='millisecond')),
|
|
|
|
('first_seen', TimestampProperty()),
|
|
|
|
('last_seen', TimestampProperty()),
|
|
|
|
('count', IntegerProperty()),
|
|
|
|
('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)),
|
|
|
|
])
|
2017-03-31 21:52:27 +02:00
|
|
|
|
|
|
|
# Explicitly define the first kwargs to make readable Sighting declarations.
|
|
|
|
def __init__(self, sighting_of_ref=None, **kwargs):
|
|
|
|
# Allow sighting_of_ref as a positional arg.
|
|
|
|
if sighting_of_ref and not kwargs.get('sighting_of_ref'):
|
|
|
|
kwargs['sighting_of_ref'] = sighting_of_ref
|
|
|
|
|
|
|
|
super(Sighting, self).__init__(**kwargs)
|