feat(server): #21109 support leading wildcards in resource matching o…#21110
Conversation
…atching of event triggers
2a809ee to
0dc2463
Compare
desertaxle
left a comment
There was a problem hiding this comment.
Thanks for the contribution @clifflau1120 ! The in-memory matching change looks correct directionally, but I think there are a few things that need to be addressed before this is ready to merge:
- Handle the double-wildcard case (
*foo*)
As written, a pattern like *middle* will hit the startswith("*") branch and do value.endswith("middle*") — matching on a literal trailing *, which is almost certainly not what a user would intend. This needs to be handled, either as a contains check or explicitly rejected with a validation error:
if expected.startswith("*") and expected.endswith("*") and len(expected) > 1:
match = expected[1:-1] in value
elif expected.startswith("*"):
match = value.endswith(expected[1:])
elif expected.endswith("*"):
match = value.startswith(expected[:-1])LabelOperationsinfilters.pyneeds matching changes
This is the important one. The LabelOperations class translates wildcard patterns into SQL for database queries, and it currently only understands trailing wildcards (→ startswith/LIKE 'prefix%') or exact match. A leading wildcard like *.csv will fall into the simple (exact match) bucket and generate resource_id IN ('*.csv') instead of the correct LIKE '%.csv'.
This means triggers will evaluate events correctly in real-time (in-memory path), but historical event queries and the events API will silently return wrong results (DB path).
- Minor things
- The docstring on
matches()should be updated to mention leading wildcards - The original test case
("any.old.*", "any.old.stuff")was removed rather than kept alongside the new case — would be good to keep it for trailing-wildcard coverage - Worth adding test cases for the negation + leading wildcard combo (
"!*.csv")
Overview
This PR closes #21109.
It adds support to leading wildcards while matching resources against events.
Checklist
<link to issue>"mint.json.