-
Notifications
You must be signed in to change notification settings - Fork 18
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
Support filters in YAML path #181
Comments
Just noticed that jsonpath-ng also has an update function. This could replace the whole self-built path parse & replace. It also works in combination with ruamel.yaml because it only operates on the loaded python objects. WIP on branch feat/json-path |
I would change the implementation in the back for all cli functions instead of using a feature flag. Reasoning: Feature flag could be great for testing, but in the long term will increase support and maintenance / testing efforts. |
Use library `jsonpath-ng` to replace own but limited JSONPath implementation. Especially the filter expressions allow more complex replacements within lists. Resolves #181.
Use library `jsonpath-ng` to replace own but limited JSONPath implementation. Especially the filter expressions allow more complex replacements within lists. Resolves #181.
Use library `jsonpath-ng` to replace own but limited JSONPath implementation. Especially the filter expressions allow more complex replacements within lists. Example: `backend.env[?name=='TEST'].value` Resolves #181.
🎉 This issue has been resolved in version 5.3.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
The replace mechanism only supports selecting the YAML path by object key and array index (e.g.
foo.bar.[0].baz
). This is quite fragile if you have to replace within arrays.Example:
or
Replacing the image tags or the env values requires the array to be in a stable order. Also the replacement path is hard to read if you don't know the YAML file:
myapp.env.[1].value
-> are we replacingFOO
orBAR
here?Possible solution:
JsonPath has filter expressions. Selecting the value of
FOO
would look like this:myapp.env[?(@.name=='FOO')].value
There is a python library jsonpath-ng which can output the matching paths:
Those returned
full_path
strings are exactly the simplified YAML path supported by the GitOpsCLI. We could just plug this library in between and translate complicated JsonPath expressions.The library even has a short form to specify the filters:
myapp.env[?name=='FOO'].value
This solution would be backwards compatible. However, we could also choose to just enable this JsonPath translation feature via CLI flag. Any opinions on that?
The text was updated successfully, but these errors were encountered: