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

[local.Driver] Move query violation binding logic to Go #177

Closed
willbeason opened this issue Dec 16, 2021 · 3 comments
Closed

[local.Driver] Move query violation binding logic to Go #177

willbeason opened this issue Dec 16, 2021 · 3 comments

Comments

@willbeason
Copy link
Member

Don't modify Rego code for this!

It's fine for the Rego to still construct the violation binding, what we care about is using Go to get the values that are already in the Result's Expressions.

This is what the rego.Result type looks like as returned by eval:

{
  "expressions": [
    {
      "value": {
        "msg": "yep"
      },
      "text": "data.hooks.violation[result]",
      "location": {
        "row": 1,
        "col": 1
      }
    }
  ],
  "bindings": {
    "result": {
      "msg": "yep"
    }
  }
}

Note that all that bindings does is provide us a convenient place to get msg from when it's already present in expressions. So we can just fetch the message from expressions. Later (in a different issue), this means we'll be able to remove the result bindings definition in Rego from gatekeeper.

Specifically: in local.Driver.Query(), for each Expression in each rego.Result in rs, add an element to var results []*types.Result if text is "data.hooks.violation[result]" which contains the contents of "value.msg".

The test code shouldn't need to change for this (unless you're just making it easier to read).

@willbeason willbeason added this to the Rego Environment Sharding milestone Dec 16, 2021
@willbeason willbeason changed the title Move query violation binding logic to Go [local.Driver] Move query violation binding logic to Go Dec 16, 2021
@willbeason willbeason removed this from the Rego Environment Sharding milestone Feb 1, 2022
@willbeason
Copy link
Member Author

Moved out of the "Rego Environment Sharding" milestone as environment sharding is required to do this properly. It isn't until we're running one query per Constraint that we can do all of this within Go.

@willbeason
Copy link
Member Author

(So this will be part of improving performance, but it's not a requirement and can't be done for now)

@willbeason
Copy link
Member Author

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant