Statement-type definitions will now match the timestamp precision given to them

master
Zach Rush 2019-09-09 21:38:58 -04:00
parent 886ef8464d
commit 53db47b447
2 changed files with 11 additions and 8 deletions

View File

@ -128,6 +128,16 @@ class MarkingDefinition(_STIXBase, _MarkingsMixin):
self._properties.update([
('created', TimestampProperty(default=lambda: NOW, precision='millisecond')),
])
else:
try:
#statement instances will match the precision given
if kwargs['created'].rfind('.') != -1:
self._properties = copy.deepcopy(self._properties)
self._properties.update([
('created', TimestampProperty(default=lambda: NOW, precision='millisecond')),
])
except AttributeError:
pass
if not isinstance(kwargs['definition'], marking_type):
defn = _get_dict(kwargs['definition'])

View File

@ -146,7 +146,7 @@ class MarkingDefinition(_STIXBase, _MarkingsMixin):
('spec_version', StringProperty(fixed='2.1')),
('id', IDProperty(_type)),
('created_by_ref', ReferenceProperty(type='identity')),
('created', TimestampProperty(default=lambda: NOW)),
('created', TimestampProperty(default=lambda: NOW, precision='millisecond')),
('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(type='marking-definition'))),
('granular_markings', ListProperty(GranularMarking)),
@ -162,13 +162,6 @@ class MarkingDefinition(_STIXBase, _MarkingsMixin):
except KeyError:
raise ValueError("definition_type must be a valid marking type")
if marking_type == TLPMarking:
# TLP instances in the spec have millisecond precision unlike other markings
self._properties = copy.deepcopy(self._properties)
self._properties.update([
('created', TimestampProperty(default=lambda: NOW, precision='millisecond')),
])
if not isinstance(kwargs['definition'], marking_type):
defn = _get_dict(kwargs['definition'])
kwargs['definition'] = marking_type(**defn)