Convert more fields to Property classes.
parent
7ef6e20e9a
commit
a79df01449
|
@ -65,20 +65,15 @@ class _STIXBase(collections.Mapping):
|
|||
prop_metadata.get('default', lambda x: ''))(cls),
|
||||
)
|
||||
raise ValueError(msg)
|
||||
elif prop_metadata.get('fixed'):
|
||||
if kwargs[prop_name] != prop_metadata['fixed']:
|
||||
msg = prop_metadata.get('error_msg', DEFAULT_ERROR).format(
|
||||
type=class_name,
|
||||
field=prop_name,
|
||||
expected=prop_metadata['fixed']
|
||||
)
|
||||
raise ValueError(msg)
|
||||
|
||||
def _check_property(self, prop_name, prop, kwargs):
|
||||
if prop_name not in kwargs:
|
||||
if hasattr(prop, 'default'):
|
||||
kwargs[prop_name] = prop.default()
|
||||
# if default == NOW:
|
||||
# kwargs[prop_name] = self.__now
|
||||
|
||||
if prop_name in kwargs:
|
||||
try:
|
||||
kwargs[prop_name] = prop.validate(kwargs[prop_name])
|
||||
except ValueError as exc:
|
||||
|
|
|
@ -11,7 +11,7 @@ class Bundle(_STIXBase):
|
|||
'type': TypeProperty(_type),
|
||||
'id': IDProperty(_type),
|
||||
'spec_version': Property(fixed="2.0"),
|
||||
'objects': {},
|
||||
'objects': Property(),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
"""STIX 2 Common Data Types and Properties"""
|
||||
|
||||
import re
|
||||
|
||||
from .base import _STIXBase
|
||||
from .properties import Property
|
||||
from .utils import NOW
|
||||
|
||||
ref_regex = ("^[a-z][a-z-]+[a-z]--[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}"
|
||||
|
@ -33,12 +35,10 @@ COMMON_PROPERTIES = {
|
|||
|
||||
class ExternalReference(_STIXBase):
|
||||
_properties = {
|
||||
'source_name': {
|
||||
'required': True,
|
||||
},
|
||||
'description': {},
|
||||
'url': {},
|
||||
'external_id': {},
|
||||
'source_name': Property(required=True),
|
||||
'description': Property(),
|
||||
'url': Property(),
|
||||
'external_id': Property(),
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ FOO_PRE_ATTACK = """{
|
|||
}"""
|
||||
|
||||
|
||||
def test_lockheed_martin_cyber_kill_chain():
|
||||
def test_kill_chain_example():
|
||||
preattack = stix2.KillChainPhase(
|
||||
kill_chain_name="foo",
|
||||
phase_name="pre-attack",
|
||||
|
|
Loading…
Reference in New Issue