-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 JSON-patch and similar builtins #1617
Comments
For kubernetes mutating admission control, would be helpful to be able produce the equivalent JSON patch for these operations. As in:
|
For lookup with a default value, what about a new operator instead of a built-in function? In most cases you want to select a deeply nested value and fallback to the default value if any of the intermediate values are undefined. With the built-in function, if intermediate values are undefined in the first operand, the overall expression will be undefined. For example, to select "c" from
You see this in some policies in the wild today. What you want to write is something like:
Just my 2c. EDIT: The other built-ins look great. Ref #1143 |
I've heard people wanting object.union to resolve conflicts the other way. Fine by me. |
For comparison, SQLite has some json operators: https://www.sqlite.org/json1.html. Noteworthy items...
|
For json_patch, the return value may need to be a go-like combination of errors and the result so that the caller can do the appropriate thing with errors, e.g. send them back up to the client. For Gatekeeper, we should ensure that a sequence of mutations can properly return those errors to the client. |
Pseudo-code for json.filter. JSON-filter first converts an array/set of path strings into an object that has exactly the same paths where the value for each path is Start with some tests
Now the pseudo-code. Below we are using Python-style list and object comprehensions. Also mixing in a little Rego semantics: the expression “if p2 := p[k]” means that if k is a key in object p then p2 is assigned the value p[k].
Unit tests for the string to object converter.
Pseudo-code for stringPaths2Object. Walk each path and add it to our result object. Only tricky part is handling conflicts, e.g. a/b and a/b/c. Want to keep just a/b.
Note: the algorithm for |
The new builtin takes an object and list of paths to keep. Reference: open-policy-agent#1617 Signed-off-by: Patrick East <east.patrick@gmail.com>
This commit adds in the following built-ins: `object.remove` `object.union` `object.filter` All of which are helpers for object manipulation in policies. Reference: open-policy-agent#1617 Signed-off-by: Patrick East <east.patrick@gmail.com>
The new builtin takes an object and list of paths to keep. Reference: open-policy-agent#1617 Signed-off-by: Patrick East <east.patrick@gmail.com>
The new builtin takes an object and list of paths to keep. Reference: #1617 Signed-off-by: Patrick East <east.patrick@gmail.com>
I'm having a lot of difficulties writing good tests without an ability to add/remove values from a given object. Is there an expected timeline for object.add/remove/union features? |
This commit adds in the following built-ins: `object.remove` `object.union` `object.filter` All of which are helpers for object manipulation in policies. Reference: open-policy-agent#1617 Signed-off-by: Patrick East <east.patrick@gmail.com>
This commit adds in the following built-ins: `object.remove` `object.union` `object.filter` All of which are helpers for object manipulation in policies. Reference: #1617 Signed-off-by: Patrick East <east.patrick@gmail.com>
This adds in a new built-in function `json.remove` which will take in an object and list of json pointer paths (similar to `json.filter`) and create a new object with all of the paths removed from the base object. Reference: open-policy-agent#1617 Signed-off-by: Patrick East <east.patrick@gmail.com>
This adds in a new built-in function `json.remove` which will take in an object and list of json pointer paths (similar to `json.filter`) and create a new object with all of the paths removed from the base object. Reference: #1617 Signed-off-by: Patrick East <east.patrick@gmail.com>
This issue has been addressed: https://www.openpolicyagent.org/docs/latest/policy-reference/#objects with the exception of the full-blown JSON Patch built-in. However, we have |
A builtin that applies a JSON patch to JSON to produce a new JSON object would be valuable in a couple of circumstances, e.g. for Kubernetes mutation policies and for application data-filtering (without query rewriting).
Additionally, it would be useful to support basic builtins for manipulating JSON objects as a simple way to derive new objects from existing objects (when JSON-patch is overkill). Including the common get(obj, key, default-value) idiom would also be valuable.
Here is a proposal:
The following builtins uplevel these kinds of operations to full JSON paths
4. JSON Patch. Follow JSON patch RFC
The text was updated successfully, but these errors were encountered: