New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add regex matching to resource attribute filters #535
Add regex matching to resource attribute filters #535
Conversation
7e18dbb
to
789647f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally expect AND behavior if I put two conditions together, and OR behavior if I put two conditions separately.
But then again, a regex is strictly more expressive than a prefix, so its probably fine to take either approach. Or we could only allow one of [Prefix, regex] and leave our options open for the future |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave the decision up to you.
789647f
to
ba5aa4c
Compare
I like it. To your point about expressiveness, I can't think of a case where someone would want to AND a prefix+regex that couldn't be expressed in one regex. But I could see the separation making configs a little more readable, if someone chooses to do that. Made the change, please double check my logic makes sense. |
matchesRegex = matched | ||
} | ||
if strings.HasPrefix(k, resourceFilter.Prefix) && matchesRegex { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matchesRegex = matched | |
} | |
if strings.HasPrefix(k, resourceFilter.Prefix) && matchesRegex { | |
if !matched { | |
continue | |
} | |
} | |
if strings.HasPrefix(k, resourceFilter.Prefix) { |
Seems simpler not to track matchesRegex separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking out the error handling made it easier for me to just do both checks in the if
. I had trouble reusing the matched
variable from the regexp call because I was declaring a new err
on the same line. It's better now
ba5aa4c
to
9bf7f21
Compare
Fixes #447 by adding a
Regex
field to resource filters. There are no restrictions on this field, so for example it is ok to setPrefix
andRegex
. The code will simply do an OR check if one of them matches.