Apply OrderedDict changes to other.py

stix2.1
Emmanuelle Vargas-Gonzalez 2017-08-14 10:34:53 -04:00
parent e2c9ecccaf
commit 81c9eab730
1 changed files with 39 additions and 31 deletions

View File

@ -1,5 +1,7 @@
"""STIX 2.0 Objects that are neither SDOs nor SROs""" """STIX 2.0 Objects that are neither SDOs nor SROs"""
from collections import OrderedDict
from .base import _STIXBase from .base import _STIXBase
from .properties import (IDProperty, ListProperty, Property, ReferenceProperty, from .properties import (IDProperty, ListProperty, Property, ReferenceProperty,
SelectorProperty, StringProperty, TimestampProperty, SelectorProperty, StringProperty, TimestampProperty,
@ -8,12 +10,13 @@ from .utils import NOW, get_dict
class ExternalReference(_STIXBase): class ExternalReference(_STIXBase):
_properties = { _properties = OrderedDict()
'source_name': StringProperty(required=True), _properties = _properties.update([
'description': StringProperty(), ('source_name', StringProperty(required=True)),
'url': StringProperty(), ('description', StringProperty()),
'external_id': StringProperty(), ('url', StringProperty()),
} ('external_id', StringProperty()),
])
def _check_object_constraints(self): def _check_object_constraints(self):
super(ExternalReference, self)._check_object_constraints() super(ExternalReference, self)._check_object_constraints()
@ -21,30 +24,34 @@ class ExternalReference(_STIXBase):
class KillChainPhase(_STIXBase): class KillChainPhase(_STIXBase):
_properties = { _properties = OrderedDict()
'kill_chain_name': StringProperty(required=True), _properties = _properties.update([
'phase_name': StringProperty(required=True), ('kill_chain_name', StringProperty(required=True)),
} ('phase_name', StringProperty(required=True)),
])
class GranularMarking(_STIXBase): class GranularMarking(_STIXBase):
_properties = { _properties = OrderedDict()
'marking_ref': ReferenceProperty(required=True, type="marking-definition"), _properties = _properties.update([
'selectors': ListProperty(SelectorProperty, required=True), ('marking_ref', ReferenceProperty(required=True, type="marking-definition")),
} ('selectors', ListProperty(SelectorProperty, required=True)),
])
class TLPMarking(_STIXBase): class TLPMarking(_STIXBase):
# TODO: don't allow the creation of any other TLPMarkings than the ones below # TODO: don't allow the creation of any other TLPMarkings than the ones below
_properties = { _properties = OrderedDict()
'tlp': Property(required=True) _properties = _properties.update([
} ('tlp', Property(required=True))
])
class StatementMarking(_STIXBase): class StatementMarking(_STIXBase):
_properties = { _properties = OrderedDict()
'statement': StringProperty(required=True) _properties = _properties.update([
} ('statement', StringProperty(required=True))
])
def __init__(self, statement=None, **kwargs): def __init__(self, statement=None, **kwargs):
# Allow statement as positional args. # Allow statement as positional args.
@ -68,17 +75,18 @@ class MarkingProperty(Property):
class MarkingDefinition(_STIXBase): class MarkingDefinition(_STIXBase):
_type = 'marking-definition' _type = 'marking-definition'
_properties = { _properties = OrderedDict()
'created': TimestampProperty(default=lambda: NOW), _properties = _properties.update([
'external_references': ListProperty(ExternalReference), ('created', TimestampProperty(default=lambda: NOW)),
'created_by_ref': ReferenceProperty(type="identity"), ('external_references', ListProperty(ExternalReference)),
'object_marking_refs': ListProperty(ReferenceProperty(type="marking-definition")), ('created_by_ref', ReferenceProperty(type="identity")),
'granular_markings': ListProperty(GranularMarking), ('object_marking_refs', ListProperty(ReferenceProperty(type="marking-definition"))),
'type': TypeProperty(_type), ('granular_markings', ListProperty(GranularMarking)),
'id': IDProperty(_type), ('type', TypeProperty(_type)),
'definition_type': StringProperty(required=True), ('id', IDProperty(_type)),
'definition': MarkingProperty(required=True), ('definition_type', StringProperty(required=True)),
} ('definition', MarkingProperty(required=True)),
])
marking_map = { marking_map = {
'tlp': TLPMarking, 'tlp': TLPMarking,
'statement': StatementMarking, 'statement': StatementMarking,