2017-02-10 22:35:02 +01:00
|
|
|
"""STIX 2.0 Relationship Objects."""
|
|
|
|
|
|
|
|
from .base import _STIXBase
|
|
|
|
from .common import COMMON_PROPERTIES
|
2017-04-25 00:29:56 +02:00
|
|
|
from .properties import (IDProperty, IntegerProperty, ListProperty,
|
|
|
|
ReferenceProperty, StringProperty, TimestampProperty,
|
|
|
|
TypeProperty)
|
2017-02-10 22:35:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Relationship(_STIXBase):
|
|
|
|
|
|
|
|
_type = 'relationship'
|
|
|
|
_properties = COMMON_PROPERTIES.copy()
|
|
|
|
_properties.update({
|
2017-02-24 17:20:24 +01:00
|
|
|
'id': IDProperty(_type),
|
2017-02-24 17:46:21 +01:00
|
|
|
'type': TypeProperty(_type),
|
2017-04-18 15:21:38 +02:00
|
|
|
'relationship_type': StringProperty(required=True),
|
|
|
|
'description': StringProperty(),
|
2017-03-31 21:52:27 +02:00
|
|
|
'source_ref': ReferenceProperty(required=True),
|
|
|
|
'target_ref': ReferenceProperty(required=True),
|
2017-02-10 22:35:02 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
# Explicitly define the first three kwargs to make readable Relationship declarations.
|
|
|
|
def __init__(self, source_ref=None, relationship_type=None, target_ref=None,
|
|
|
|
**kwargs):
|
|
|
|
# TODO:
|
|
|
|
# - description
|
|
|
|
|
|
|
|
# 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-03-31 21:52:27 +02:00
|
|
|
class Sighting(_STIXBase):
|
|
|
|
_type = 'sighting'
|
|
|
|
_properties = COMMON_PROPERTIES.copy()
|
|
|
|
_properties.update({
|
|
|
|
'id': IDProperty(_type),
|
|
|
|
'type': TypeProperty(_type),
|
2017-04-18 15:21:38 +02:00
|
|
|
'first_seen': TimestampProperty(),
|
|
|
|
'last_seen': TimestampProperty(),
|
|
|
|
'count': IntegerProperty(),
|
2017-03-31 21:52:27 +02:00
|
|
|
'sighting_of_ref': ReferenceProperty(required=True),
|
2017-04-14 16:42:17 +02:00
|
|
|
'observed_data_refs': ListProperty(ReferenceProperty(type="observed-data")),
|
|
|
|
'where_sighted_refs': ListProperty(ReferenceProperty(type="identity")),
|
2017-04-18 15:21:38 +02:00
|
|
|
'summary': StringProperty(),
|
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):
|
|
|
|
# TODO:
|
|
|
|
# - description
|
|
|
|
|
|
|
|
# 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)
|