Skip to content

Commit 1e41008

Browse files
author
Bryan Worrell
committed
Replaced all referecnes to AttributeField, ElementField, and StructuredTextListField with
mixbox TypedField.
1 parent e2a8941 commit 1e41008

23 files changed

Lines changed: 166 additions & 193 deletions

stix/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Make sure base gets imported before common.
55
from .base import (Entity, EntityList, TypedCollection, TypedList, # noqa
6-
BaseCoreComponent, ElementField, AttributeField)
6+
BaseCoreComponent)
77

88
#: Mapping of xsi:types to implementation/extension classes
99
_EXTENSION_MAP = {}

stix/base.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ def _override(*args, **kwargs):
2222
raise NotImplementedError()
2323

2424

25-
class AttributeField(fields.TypedField):
26-
pass
27-
28-
29-
class ElementField(fields.TypedField):
30-
pass
31-
32-
33-
class ContentField(fields.TypedField):
34-
pass
35-
36-
3725
class Entity(entities.Entity):
3826
"""Base class for all classes in the STIX API."""
3927
_namespace = None
@@ -379,12 +367,12 @@ class BaseCoreComponent(Cached, Entity):
379367
_ALL_VERSIONS = ()
380368
_ID_PREFIX = None
381369

382-
title = ElementField("Title")
370+
title = fields.TypedField("Title")
383371
id_ = fields.IdField("id")
384372
idref = fields.IdrefField("idref")
385373
descriptions = fields.TypedField("Description", type_="stix.common.StructuredTextList", key_name="description")
386374
short_descriptions = fields.TypedField("Short_Description", type_="stix.common.StructuredTextList", key_name="short_description")
387-
version = AttributeField("version", preset_hook=_validate_version)
375+
version = fields.TypedField("version", preset_hook=_validate_version)
388376
timestamp = fields.DateTimeField("timestamp")
389377
handling = fields.TypedField("Handling", type_="stix.data_marking.Marking")
390378

stix/campaign/__init__.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (c) 2015, The MITRE Corporation. All rights reserved.
22
# See LICENSE.txt for complete terms.
33

4+
from mixbox import fields
5+
46
import stix
57
from stix.utils import deprecated
68
from stix.common import Activity, Confidence, Statement, VocabString
@@ -10,8 +12,7 @@
1012
)
1113
from stix.common import vocabs
1214
import stix.bindings.campaign as campaign_binding
13-
from stix.common.structured_text import StructuredTextList, StructuredTextListField
14-
from stix.base import ElementField, AttributeField
15+
from stix.common.structured_text import StructuredTextList
1516
from stix.common.information_source import InformationSource
1617

1718
class AssociatedCampaigns(GenericRelationshipList):
@@ -32,8 +33,8 @@ class Attribution(GenericRelationshipList):
3233

3334
"""
3435
class Attribution(stix.Entity):
35-
threat_actors = ElementField("Attributed_Threat_Actor", RelatedThreatActor, multiple=True, key_name="threat_actors")
36-
scope = AttributeField("scope")
36+
threat_actors = fields.TypedField("Attributed_Threat_Actor", RelatedThreatActor, multiple=True, key_name="threat_actors")
37+
scope = fields.TypedField("scope")
3738
3839
def __init__(self, scope=None, *args):
3940
self._fields = {}
@@ -111,19 +112,19 @@ class Campaign(stix.BaseCoreComponent):
111112
_ALL_VERSIONS = ("1.0", "1.0.1", "1.1", "1.1.1", "1.2")
112113
_ID_PREFIX = 'campaign'
113114

114-
descriptions = StructuredTextListField("Description", StructuredTextList, key_name="description")
115-
activity = ElementField("Activity", Activity, multiple=True)
116-
associated_campaigns = ElementField("Associated_Campaigns", AssociatedCampaigns)
117-
attribution = ElementField("Attribution", Attribution, multiple=True)
118-
confidence = ElementField("Confidence", Confidence)
119-
# references = ElementField("Reference", multiple=True)
120-
status = ElementField("Status", VocabString)
121-
intended_effects = ElementField("Intended_Effect", Statement, multiple=True, key_name="intended_effects")
122-
names = ElementField("Names", Names)
123-
related_incidents = ElementField("Related_Incidents", RelatedIncidents)
124-
related_indicators = ElementField("Related_Indicators", RelatedIndicators)
125-
related_packages = ElementField("Related_Packages", RelatedPackageRefs)
126-
information_source = ElementField("Information_Source", InformationSource)
115+
descriptions = fields.TypedField("Description", StructuredTextList, key_name="description")
116+
activity = fields.TypedField("Activity", Activity, multiple=True)
117+
associated_campaigns = fields.TypedField("Associated_Campaigns", AssociatedCampaigns)
118+
attribution = fields.TypedField("Attribution", Attribution, multiple=True)
119+
confidence = fields.TypedField("Confidence", Confidence)
120+
# references = fields.TypedField("Reference", multiple=True)
121+
status = fields.TypedField("Status", VocabString)
122+
intended_effects = fields.TypedField("Intended_Effect", Statement, multiple=True, key_name="intended_effects")
123+
names = fields.TypedField("Names", Names)
124+
related_incidents = fields.TypedField("Related_Incidents", RelatedIncidents)
125+
related_indicators = fields.TypedField("Related_Indicators", RelatedIndicators)
126+
related_packages = fields.TypedField("Related_Packages", RelatedPackageRefs)
127+
information_source = fields.TypedField("Information_Source", InformationSource)
127128

128129
def __init__(self, id_=None, idref=None, timestamp=None, title=None,
129130
description=None, short_description=None):

stix/common/activity.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
# Copyright (c) 2015, The MITRE Corporation. All rights reserved.
22
# See LICENSE.txt for complete terms.
33

4+
from mixbox import fields
5+
46
import stix
57
import stix.bindings.stix_common as common_binding
68
import stix.utils
7-
from stix.base import ElementField
89

910
from .datetimewithprecision import DateTimeWithPrecision
10-
from .structured_text import StructuredTextList, StructuredTextListField
11+
from .structured_text import StructuredTextList
1112

1213

1314
class Activity(stix.Entity):
1415
_binding = common_binding
1516
_binding_class = common_binding.ActivityType
1617
_namespace = 'http://stix.mitre.org/common-1'
1718

18-
date_time = ElementField("Date_Time", DateTimeWithPrecision)
19-
descriptions = StructuredTextListField("Description", StructuredTextList, key_name="description")
19+
date_time = fields.TypedField("Date_Time", DateTimeWithPrecision)
20+
descriptions = fields.TypedField("Description", StructuredTextList, key_name="description")
2021

2122
def __init__(self):
2223
super(Activity, self).__init__()

stix/common/campaign_reference.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
# See LICENSE.txt for complete terms.
33

44
# external
5-
from mixbox.fields import DateTimeField
5+
from mixbox import fields
66

77
# internal
88
import stix
99
import stix.bindings.stix_common as common_binding
10-
from stix.base import AttributeField, ElementField
1110

1211
# relative
1312
from .names import Names
@@ -18,13 +17,13 @@ class CampaignRef(stix.Entity):
1817
_binding = common_binding
1918
_binding_class = common_binding.CampaignReferenceType
2019

21-
idref = AttributeField("idref")
22-
timestamp = DateTimeField("timestamp")
23-
names = ElementField("Names", Names)
20+
idref = fields.TypedField("idref")
21+
timestamp = fields.DateTimeField("timestamp")
22+
names = fields.TypedField("Names", Names)
2423

2524
def __init__(self, idref=None, timestamp=None):
2625
super(CampaignRef, self).__init__()
27-
26+
2827
self.idref = idref
2928
self.timestamp = timestamp
3029
self.names = None

stix/common/confidence.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,26 @@
33

44
from __future__ import absolute_import
55

6-
from mixbox.fields import DateTimeField
6+
from mixbox import fields
77

88
import stix
99
import stix.utils as utils
1010
import stix.bindings.stix_common as common_binding
1111

12-
from stix.base import ElementField, AttributeField
13-
1412
from .vocabs import VocabString
15-
from .structured_text import StructuredTextList, StructuredTextListField
13+
from .structured_text import StructuredTextList
1614
from .datetimewithprecision import validate_precision
1715

1816
class Confidence(stix.Entity):
1917
_namespace = 'http://stix.mitre.org/common-1'
2018
_binding = common_binding
2119
_binding_class = common_binding.ConfidenceType
2220

23-
value = ElementField("Value", VocabString)
24-
descriptions = StructuredTextListField("Description", StructuredTextList, key_name="description")
25-
timestamp = DateTimeField("timestamp")
26-
timestamp_precision = AttributeField("timestamp_precision", preset_hook=validate_precision)
27-
source = ElementField("Source", type_="stix.common.InformationSource")
21+
value = fields.TypedField("Value", VocabString)
22+
descriptions = fields.TypedField("Description", StructuredTextList, key_name="description")
23+
timestamp = fields.DateTimeField("timestamp")
24+
timestamp_precision = fields.TypedField("timestamp_precision", preset_hook=validate_precision)
25+
source = fields.TypedField("Source", type_="stix.common.InformationSource")
2826

2927
def __init__(self, value=None, timestamp=None, description=None, source=None):
3028
super(Confidence, self).__init__()

stix/common/datetimewithprecision.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# Copyright (c) 2015, The MITRE Corporation. All rights reserved.
22
# See LICENSE.txt for complete terms.
33

4-
from mixbox.fields import DateTimeField
4+
from mixbox import fields
55

66
import stix
77
import stix.utils as utils
88
import stix.bindings.stix_common as common_binding
99

10-
from stix.base import AttributeField
1110

1211
DATE_PRECISION_VALUES = ("year", "month", "day")
1312
TIME_PRECISION_VALUES = ("hour", "minute", "second")
@@ -30,8 +29,8 @@ class DateTimeWithPrecision(stix.Entity):
3029
_binding_class = _binding.DateTimeWithPrecisionType
3130
_namespace = 'http://stix.mitre.org/common-1'
3231

33-
value = DateTimeField("valueOf_", key_name="value")
34-
precision = AttributeField("precision", preset_hook=validate_precision)
32+
value = fields.DateTimeField("valueOf_", key_name="value")
33+
precision = fields.TypedField("precision", preset_hook=validate_precision)
3534

3635
def __init__(self, value=None, precision='second'):
3736
super(DateTimeWithPrecision, self).__init__()

stix/common/identity.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# internal
99
import stix
1010
import stix.bindings.stix_common as common_binding
11-
from stix.base import ElementField
1211
from stix.bindings.stix_common import IdentityType
1312

1413

@@ -19,7 +18,7 @@ class Identity(Cached, stix.Entity):
1918

2019
id_ = fields.IdField("id")
2120
idref = fields.IdrefField("idref")
22-
name = ElementField("Name")
21+
name = fields.TypedField("Name")
2322
related_identities = fields.TypedField("Related_Identities", type_="stix.common.identity.RelatedIdentities")
2423

2524
def __init__(self, id_=None, idref=None, name=None, related_identities=None):

stix/common/information_source.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@
22
# See LICENSE.txt for complete terms.
33

44
# external
5+
from mixbox import fields
56
import cybox.common
67
from cybox.common.tools import ToolInformationList
78

89
# internal
910
import stix
10-
from stix.base import ElementField
1111
import stix.bindings.stix_common as stix_common_binding
1212

1313
# relative
1414
from .vocabs import VocabString
1515
from .references import References
1616
from .identity import Identity
17-
from .structured_text import StructuredTextList, StructuredTextListField
17+
from .structured_text import StructuredTextList
1818

1919

2020
class InformationSource(stix.Entity):
2121
_binding = stix_common_binding
2222
_binding_class = stix_common_binding.InformationSourceType
2323
_namespace = 'http://stix.mitre.org/common-1'
2424

25-
identity = ElementField("Identity", Identity)
26-
descriptions = StructuredTextListField("Description", StructuredTextList, key_name="description")
27-
contributing_sources = ElementField("Contributing_Sources", type_="stix.common.information_source.ContributingSources")
28-
time = ElementField("Time", cybox.common.Time)
29-
roles = ElementField("Role", VocabString, multiple=True, key_name="roles")
30-
tools = ElementField("Tools", ToolInformationList)
31-
references = ElementField("References", References)
25+
identity = fields.TypedField("Identity", Identity)
26+
descriptions = fields.TypedField("Description", StructuredTextList, key_name="description")
27+
contributing_sources = fields.TypedField("Contributing_Sources", type_="stix.common.information_source.ContributingSources")
28+
time = fields.TypedField("Time", cybox.common.Time)
29+
roles = fields.TypedField("Role", VocabString, multiple=True, key_name="roles")
30+
tools = fields.TypedField("Tools", ToolInformationList)
31+
references = fields.TypedField("References", References)
3232

3333
def __init__(self, description=None, identity=None, time=None, tools=None, contributing_sources=None, references=None):
3434
super(InformationSource, self).__init__()

stix/common/kill_chains/__init__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@
66
# internal
77
import stix
88
import stix.bindings.stix_common as common_binding
9-
from stix.base import AttributeField, ElementField
109

1110
class KillChain(stix.Entity):
1211
_binding = common_binding
1312
_namespace = 'http://stix.mitre.org/common-1'
1413
_binding_class = _binding.KillChainType
1514

16-
id_ = AttributeField("id")
17-
name = AttributeField("name")
18-
definer = AttributeField("definer")
19-
reference = AttributeField("reference")
20-
number_of_phases = AttributeField("number_of_phases")
21-
kill_chain_phases = ElementField("Kill_Chain_Phase", type_="stix.common.kill_chains.KillChainPhase", multiple=True, key_name="kill_chain_phases")
15+
id_ = fields.TypedField("id")
16+
name = fields.TypedField("name")
17+
definer = fields.TypedField("definer")
18+
reference = fields.TypedField("reference")
19+
number_of_phases = fields.TypedField("number_of_phases")
20+
kill_chain_phases = fields.TypedField("Kill_Chain_Phase", type_="stix.common.kill_chains.KillChainPhase", multiple=True, key_name="kill_chain_phases")
2221

2322
def __init__(self, id_=None, name=None, definer=None, reference=None):
2423
super(KillChain, self).__init__()
@@ -59,8 +58,8 @@ class KillChainPhase(stix.Entity):
5958
_namespace = 'http://stix.mitre.org/common-1'
6059
_binding_class = _binding.KillChainPhaseType
6160

62-
phase_id = AttributeField("phase_id")
63-
name = AttributeField("name")
61+
phase_id = fields.TypedField("phase_id")
62+
name = fields.TypedField("name")
6463
ordinality = fields.IntegerField("ordinality")
6564

6665
def __init__(self, phase_id=None, name=None, ordinality=None):
@@ -91,8 +90,8 @@ class KillChainPhaseReference(KillChainPhase):
9190
_namespace = 'http://stix.mitre.org/common-1'
9291
_binding_class = _binding.KillChainPhaseReferenceType
9392

94-
kill_chain_id = AttributeField("kill_chain_id")
95-
kill_chain_name = AttributeField("kill_chain_name")
93+
kill_chain_id = fields.TypedField("kill_chain_id")
94+
kill_chain_name = fields.TypedField("kill_chain_name")
9695

9796
def __init__(self, phase_id=None, name=None, ordinality=None, kill_chain_id=None, kill_chain_name=None):
9897
super(KillChainPhaseReference, self).__init__(phase_id, name, ordinality)

0 commit comments

Comments
 (0)