too Chris' suggestions to improve interproperty constraint methods
added interproperty constraint check to ExternalReferencesstix2.1
parent
29871427b7
commit
a95e91005c
|
@ -50,21 +50,16 @@ class _STIXBase(collections.Mapping):
|
||||||
# interproperty constraint methods
|
# interproperty constraint methods
|
||||||
|
|
||||||
def _check_mutually_exclusive_properties(self, list_of_properties, at_least_one=True):
|
def _check_mutually_exclusive_properties(self, list_of_properties, at_least_one=True):
|
||||||
count = 0
|
|
||||||
current_properties = self.properties_populated()
|
current_properties = self.properties_populated()
|
||||||
for x in list_of_properties:
|
count = len(set(list_of_properties).intersection(current_properties))
|
||||||
if x in current_properties:
|
|
||||||
count += 1
|
|
||||||
# at_least_one allows for xor to be checked
|
# at_least_one allows for xor to be checked
|
||||||
if count > 1 or (at_least_one and count == 0):
|
if count > 1 or (at_least_one and count == 0):
|
||||||
raise MutuallyExclusivePropertiesError(self.__class__, list_of_properties)
|
raise MutuallyExclusivePropertiesError(self.__class__, list_of_properties)
|
||||||
|
|
||||||
def _check_at_least_one_property(self, list_of_properties):
|
def _check_at_least_one_property(self, list_of_properties):
|
||||||
current_properties = self.properties_populated()
|
current_properties = self.properties_populated()
|
||||||
for x in list_of_properties:
|
if not set(list_of_properties).intersection(current_properties):
|
||||||
if x in current_properties:
|
raise AtLeastOnePropertyError(self.__class__, list_of_properties)
|
||||||
return
|
|
||||||
raise AtLeastOnePropertyError(self.__class__, list_of_properties)
|
|
||||||
|
|
||||||
def _check_properties_dependency(self, list_of_properties, list_of_dependent_properties, values=[]):
|
def _check_properties_dependency(self, list_of_properties, list_of_dependent_properties, values=[]):
|
||||||
failed_dependency_pairs = []
|
failed_dependency_pairs = []
|
||||||
|
|
|
@ -15,6 +15,10 @@ class ExternalReference(_STIXBase):
|
||||||
'external_id': StringProperty(),
|
'external_id': StringProperty(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _check_object_constaints(self):
|
||||||
|
super(ExternalReference, self)._check_object_constaints()
|
||||||
|
self._check_at_least_one_property(["description", "external_id", "url"])
|
||||||
|
|
||||||
|
|
||||||
class KillChainPhase(_STIXBase):
|
class KillChainPhase(_STIXBase):
|
||||||
_properties = {
|
_properties = {
|
||||||
|
|
Loading…
Reference in New Issue