-
Notifications
You must be signed in to change notification settings - Fork 42
feat(workflows): Allow to filter workflows using a JSON filter #1889
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
Conversation
pkg/jsonfilter/jsonfilter.go
Outdated
| const columnNotFoundSQLState = "42703" | ||
|
|
||
| // columnNotExistRegex extracts column name from the error message | ||
| var columnNotExistRegex = regexp.MustCompile(`column "([^"]+)" does not exist`) |
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'd not support dynamic selection of columns, that's an implementation detail to me that should not be exposed in then API
migmartri
left a comment
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.
Thanks @javirln, my take on this implementation
- I'd not allow dynamically supporting column selection, that's an implementation details that I do not think it should get exposed at the API layer, nevertheless I am scared that it could be a threat ventor (i.e crafting to query columns that you are not supposed to query). Instead, I'd let the data layer to decide what column the filter must be applied to.
- In the name of Yagni (which I can be quite opinionated sometimes), I'd not add any other code than the one we are going to use. This means, no more selectors than the one that we plan to use, no code is the best code.
Thanks!
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
|
The record on the database has a json value on the {"random_key": "random_value"}Examples: Filtering the value successfully: Change the operator so, no entry found: Multiple filters applied are combined using an AND. Applying the |
jiparis
left a comment
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.
Awesome, @javirln . Just one nit comment about the operator verbosity.
Thanks!
| predicates = append(predicates, jsonPredicate) | ||
| } | ||
| // Combine the predicates using OR logic | ||
| selector.Where(sql.Or(predicates...)) |
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.
interestingly, you chose to make or the default; it feels counterintuitive, no?
I mean if you provide multiple filters, my fist thought would be to become an AND. What do you think?
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.
You might be right, and I was just biassed by another PR. I've changed it to merge all filters in an AND. Thanks.
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
This patch allows to filter Workflows using a JSON filter. A JSON filter is a filter that works over JSON data in a specific column. Such data shall be stored in the database.
The JSON filter is later converted into a valid SQL statement.