Events - match full list against pattern (#4534)
This commit is contained in:
parent
aab2a25dfa
commit
3353677c72
@ -838,12 +838,13 @@ class EventPattern:
|
|||||||
def _does_item_match_filters(self, item, filters):
|
def _does_item_match_filters(self, item, filters):
|
||||||
allowed_values = [value for value in filters if isinstance(value, str)]
|
allowed_values = [value for value in filters if isinstance(value, str)]
|
||||||
allowed_values_match = item in allowed_values if allowed_values else True
|
allowed_values_match = item in allowed_values if allowed_values else True
|
||||||
|
full_match = isinstance(item, list) and item == allowed_values
|
||||||
named_filter_matches = [
|
named_filter_matches = [
|
||||||
self._does_item_match_named_filter(item, pattern)
|
self._does_item_match_named_filter(item, pattern)
|
||||||
for pattern in filters
|
for pattern in filters
|
||||||
if isinstance(pattern, dict)
|
if isinstance(pattern, dict)
|
||||||
]
|
]
|
||||||
return allowed_values_match and all(named_filter_matches)
|
return (full_match or allowed_values_match) and all(named_filter_matches)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _does_item_match_named_filter(item, pattern):
|
def _does_item_match_named_filter(item, pattern):
|
||||||
|
@ -16,6 +16,8 @@ def test_event_pattern_with_nested_event_filter():
|
|||||||
pattern = EventPattern.load(json.dumps({"detail": {"foo": ["bar"]}}))
|
pattern = EventPattern.load(json.dumps({"detail": {"foo": ["bar"]}}))
|
||||||
assert pattern.matches_event({"detail": {"foo": "bar"}})
|
assert pattern.matches_event({"detail": {"foo": "bar"}})
|
||||||
assert not pattern.matches_event({"detail": {"foo": "baz"}})
|
assert not pattern.matches_event({"detail": {"foo": "baz"}})
|
||||||
|
# The full list should match as well
|
||||||
|
assert pattern.matches_event({"detail": {"foo": ["bar"]}})
|
||||||
|
|
||||||
|
|
||||||
def test_event_pattern_with_exists_event_filter():
|
def test_event_pattern_with_exists_event_filter():
|
||||||
|
Loading…
Reference in New Issue
Block a user