-
Notifications
You must be signed in to change notification settings - Fork 43
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
Complete builtin coverage #23
Comments
Are there plans to allow the user to add builtins? The documentation says http could be implemented (for instance) but I don't think this package exposes that behavior? |
Potentially, but it starts to have implications for portability of Rego policies. The behavior of some part of a policy may change if there are external implementations of the like standard builtin functions. What we would probably want to do is allow for custom builtin functions to be defined by a user, similar to the golang API for OPA https://www.openpolicyagent.org/docs/latest/extensions/ |
That would be really useful for me! Can I help implement? |
After a quick review of the WASM stuff in OPA it seems like maybe the SDK wouldn't be able to distinguish between the like OPA builtins and a custom one. So I guess what we would need to do is add an API into https://github.com/open-policy-agent/npm-opa-wasm/blob/master/src/opa.js which basically extends the function map Line 69 in f4be0d0
Lines 79 to 104 in f4be0d0
For anyone who compiles with a custom function (which would require using the OPA Golang API's to provide the function definition) it would call out into the SDK, and as long as there is one with the right name in that function map everything should be OK. I guess for your original question around adding HTTP support, that gives you a potential hook to do it there. |
I am able to monkey-patch the ./builtIn import to provide some implementations needed to evaluate some rego we use. And you are right it appears that it won't differentiate. Would it be reasonable to add an option I think I can put that together pretty quick |
Allowing users to add there own implementation of a builtin makes sense to me. This makes sure that the user can use this library as is, even if it's not up to date because a certain builtin is not yet supported. |
This adds support for custom builtins by adding an additional parameter to loadPolicy, somewhat related to the discussion in #23. One potential point of contention is that this always favors first-party builtins over provided builtins. Signed-off-by: Adam Berger <[email protected]>
As-is the SDK has a few builtins added:
And the list that OPA includes baked into the WASM binary is increasing, current list at: https://github.com/open-policy-agent/opa/blob/master/internal/planner/planner.go#L26
But there are still a number of missing ones (ex: #22 ).
Before we do anything we need to identify what functions are missing, and how we want to stay in sync with OPA. Over time it will include more builtins, so we will need to slowly deprecate and remove the ones we provide in the javascript SDK. We should figure out a plan for that..
We also need to document any missing functions to help users of the SDK understand what they can and cannot do with the SDK in its current form.
The text was updated successfully, but these errors were encountered: