Skip to content
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

Allow for JSON string to be processed in the Sensor DataFilter #1097

Closed
jayfray12 opened this issue Mar 4, 2021 · 1 comment
Closed

Allow for JSON string to be processed in the Sensor DataFilter #1097

jayfray12 opened this issue Mar 4, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@jayfray12
Copy link
Contributor

jayfray12 commented Mar 4, 2021

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
When using gjson to evaluate the path of the DataFilter it returns a Result. You are using Result.Str here. With gjson you can return a JSON object by utilizing a Multipath. However, when utilizing this Multipath the Result.Type is JSON and thus the Result.Str returns an empty string and nothing is ever matched by the filter. You can however call Result.String() which correctly returns the string based on the Result.Type.

Describe the solution you'd like
A clear and concise description of what you want to happen.
What I'm trying to achieve is I have a webhook defined for an event and I want to filter the calls based on a value and depending on that value I may or may not want to filter if another value is something. For example:

{
  "body": {
    "action":"opened",
    "labels": [
      {"id":"1234", "name":"Webhook"}, 
      {"id":"5678", "name":"Approved"}
    ]
  }
}

I want the sensor to fire if my action is "opened" and it has a label of "Webhook" or if the action is "closed" and it has a label of "Webhook" and "Approved". Given the value of the DataFilter can be a regex I can use the gjson syntax to do something like:

[body.action,body.labels.#(name=="Webhook").name,body.labels.#(name=="Approved").name]

This produces a String like this:

["opened","Webhook","Approved"]

Then I could do a regex with something like:

(\bopened\b.*\bWebhook\b)|(\blabeled\b.*(\bWebhook\b.*\bApproved\b))

To filter the way I want. However, like I mentioned above the Result.Str is empty when the Result.Type is JSON and thus would need to code changed to call Result.String()

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
I tried I ton of different ways to filter based on what I want but can't come up with anything else.

Additional context
Add any other context or screenshots about the feature request here.


Message from the maintainers:

If you wish to see this enhancement implemented please add a 👍 reaction to this issue! We often sort issues this way to know what to prioritize.

@jayfray12
Copy link
Contributor Author

Issue resolved with PR

tico24 added a commit to tico24/argo-events that referenced this issue Mar 24, 2021
tico24 added a commit to tico24/argo-events that referenced this issue Mar 24, 2021
whynowy pushed a commit that referenced this issue Mar 24, 2021
* docs: Enhance the filters tutorial for #1097

Signed-off-by: Tim Collins <[email protected]>
whynowy pushed a commit that referenced this issue Mar 24, 2021
* docs: Enhance the filters tutorial for #1097

Signed-off-by: Tim Collins <[email protected]>
juliev0 pushed a commit to juliev0/argo-events that referenced this issue Mar 29, 2022
* docs: Enhance the filters tutorial for argoproj#1097

Signed-off-by: Tim Collins <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant