Convert most old-style properties to Property classes

stix2.1
Greg Back 2017-03-21 20:06:09 -04:00
parent 19146c8327
commit 9bcf064213
3 changed files with 70 additions and 114 deletions

View File

@ -14,7 +14,7 @@ COMMON_PROPERTIES = {
'modified': { 'modified': {
'default': NOW, 'default': NOW,
}, },
'external_references': {}, 'external_references': Property(),
'revoked': BooleanProperty(), 'revoked': BooleanProperty(),
'created_by_ref': ReferenceProperty(), 'created_by_ref': ReferenceProperty(),
} }
@ -31,10 +31,6 @@ class ExternalReference(_STIXBase):
class KillChainPhase(_STIXBase): class KillChainPhase(_STIXBase):
_properties = { _properties = {
'kill_chain_name': { 'kill_chain_name': Property(required=True),
'required': True, 'phase_name': Property(required=True),
},
'phase_name': {
'required': True,
},
} }

View File

@ -2,7 +2,7 @@
from .base import _STIXBase from .base import _STIXBase
from .common import COMMON_PROPERTIES from .common import COMMON_PROPERTIES
from .properties import IDProperty, TypeProperty from .properties import IDProperty, TypeProperty, Property
from .utils import NOW from .utils import NOW
@ -13,11 +13,9 @@ class AttackPattern(_STIXBase):
_properties.update({ _properties.update({
'type': TypeProperty(_type), 'type': TypeProperty(_type),
'id': IDProperty(_type), 'id': IDProperty(_type),
'name': { 'name': Property(required=True),
'required': True, 'description': Property(),
}, 'kill_chain_phases': Property(),
'description': {},
'kill_chain_phases': {},
}) })
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -40,14 +38,12 @@ class Campaign(_STIXBase):
_properties.update({ _properties.update({
'type': TypeProperty(_type), 'type': TypeProperty(_type),
'id': IDProperty(_type), 'id': IDProperty(_type),
'name': { 'name': Property(required=True),
'required': True, 'description': Property(),
}, 'aliases': Property(),
'description': {}, 'first_seen': Property(),
'aliases': {}, 'last_seen': Property(),
'first_seen': {}, 'objective': Property(),
'last_seen': {},
'objective': {},
}) })
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -73,10 +69,8 @@ class CourseOfAction(_STIXBase):
_properties.update({ _properties.update({
'type': TypeProperty(_type), 'type': TypeProperty(_type),
'id': IDProperty(_type), 'id': IDProperty(_type),
'name': { 'name': Property(required=True),
'required': True, 'description': Property(),
},
'description': {},
}) })
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -98,15 +92,11 @@ class Identity(_STIXBase):
_properties.update({ _properties.update({
'type': TypeProperty(_type), 'type': TypeProperty(_type),
'id': IDProperty(_type), 'id': IDProperty(_type),
'name': { 'name': Property(required=True),
'required': True, 'description': Property(),
}, 'identity_class': Property(required=True),
'description': {}, 'sectors': Property(),
'identity_class': { 'contact_information': Property(),
'required': True,
},
'sectors': {},
'contact_information': {},
}) })
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -131,19 +121,15 @@ class Indicator(_STIXBase):
_properties.update({ _properties.update({
'type': TypeProperty(_type), 'type': TypeProperty(_type),
'id': IDProperty(_type), 'id': IDProperty(_type),
'labels': { 'labels': Property(required=True),
'required': True, 'name': Property(),
}, 'description': Property(),
'name': {}, 'pattern': Property(required=True),
'description': {},
'pattern': {
'required': True,
},
'valid_from': { 'valid_from': {
'default': NOW, 'default': NOW,
}, },
'valid_until': {}, 'valid_until': Property(),
'kill_chain_phases': {}, 'kill_chain_phases': Property(),
}) })
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -168,17 +154,15 @@ class IntrusionSet(_STIXBase):
_properties.update({ _properties.update({
'type': TypeProperty(_type), 'type': TypeProperty(_type),
'id': IDProperty(_type), 'id': IDProperty(_type),
'name': { 'name': Property(required=True),
'required': True, 'description': Property(),
}, 'aliases': Property(),
'description': {}, 'first_seen': Property(),
'aliases': {}, 'last_seen ': Property(),
'first_seen': {}, 'goals': Property(),
'last_seen ': {}, 'resource_level': Property(),
'goals': {}, 'primary_motivation': Property(),
'resource_level': {}, 'secondary_motivations': Property(),
'primary_motivation': {},
'secondary_motivations': {},
}) })
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -207,14 +191,10 @@ class Malware(_STIXBase):
_properties.update({ _properties.update({
'type': TypeProperty(_type), 'type': TypeProperty(_type),
'id': IDProperty(_type), 'id': IDProperty(_type),
'labels': { 'labels': Property(required=True),
'required': True, 'name': Property(required=True),
}, 'description': Property(),
'name': { 'kill_chain_phases': Property(),
'required': True,
},
'description': {},
'kill_chain_phases': {},
}) })
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -237,10 +217,10 @@ class ObservedData(_STIXBase):
_properties.update({ _properties.update({
'type': TypeProperty(_type), 'type': TypeProperty(_type),
'id': IDProperty(_type), 'id': IDProperty(_type),
'first_observed': {}, 'first_observed': Property(),
'last_observed': {}, 'last_observed': Property(),
'number_observed': {}, 'number_observed': Property(),
'objects': {}, 'objects': Property(),
}) })
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -265,15 +245,11 @@ class Report(_STIXBase):
_properties.update({ _properties.update({
'type': TypeProperty(_type), 'type': TypeProperty(_type),
'id': IDProperty(_type), 'id': IDProperty(_type),
'labels': { 'labels': Property(required=True),
'required': True, 'name': Property(required=True),
}, 'description': Property(),
'name': { 'published': Property(),
'required': True, 'object_refs': Property(),
},
'description': {},
'published': {},
'object_refs': {},
}) })
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -297,21 +273,17 @@ class ThreatActor(_STIXBase):
_properties.update({ _properties.update({
'type': TypeProperty(_type), 'type': TypeProperty(_type),
'id': IDProperty(_type), 'id': IDProperty(_type),
'labels': { 'labels': Property(required=True),
'required': True, 'name': Property(required=True),
}, 'description': Property(),
'name': { 'aliases': Property(),
'required': True, 'roles': Property(),
}, 'goals': Property(),
'description': {}, 'sophistication': Property(),
'aliases': {}, 'resource_level': Property(),
'roles': {}, 'primary_motivation': Property(),
'goals': {}, 'secondary_motivations': Property(),
'sophistication': {}, 'personal_motivations': Property(),
'resource_level': {},
'primary_motivation': {},
'secondary_motivations': {},
'personal_motivations': {},
}) })
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -341,15 +313,11 @@ class Tool(_STIXBase):
_properties.update({ _properties.update({
'type': TypeProperty(_type), 'type': TypeProperty(_type),
'id': IDProperty(_type), 'id': IDProperty(_type),
'labels': { 'labels': Property(required=True),
'required': True, 'name': Property(required=True),
}, 'description': Property(),
'name': { 'kill_chain_phases': Property(),
'required': True, 'tool_version': Property(),
},
'description': {},
'kill_chain_phases': {},
'tool_version': {},
}) })
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -373,10 +341,8 @@ class Vulnerability(_STIXBase):
_properties.update({ _properties.update({
'type': TypeProperty(_type), 'type': TypeProperty(_type),
'id': IDProperty(_type), 'id': IDProperty(_type),
'name': { 'name': Property(required=True),
'required': True, 'description': Property(),
},
'description': {},
}) })
def __init__(self, **kwargs): def __init__(self, **kwargs):

View File

@ -2,7 +2,7 @@
from .base import _STIXBase from .base import _STIXBase
from .common import COMMON_PROPERTIES from .common import COMMON_PROPERTIES
from .properties import IDProperty, TypeProperty from .properties import IDProperty, TypeProperty, Property
class Relationship(_STIXBase): class Relationship(_STIXBase):
@ -12,15 +12,9 @@ class Relationship(_STIXBase):
_properties.update({ _properties.update({
'id': IDProperty(_type), 'id': IDProperty(_type),
'type': TypeProperty(_type), 'type': TypeProperty(_type),
'relationship_type': { 'relationship_type': Property(required=True),
'required': True, 'source_ref': Property(required=True),
}, 'target_ref': Property(required=True),
'source_ref': {
'required': True,
},
'target_ref': {
'required': True,
},
}) })
# Explicitly define the first three kwargs to make readable Relationship declarations. # Explicitly define the first three kwargs to make readable Relationship declarations.