opa icon indicating copy to clipboard operation
opa copied to clipboard

Add `rego.Data` function to simply add data from map

Open anderseknert opened this issue 1 year ago • 8 comments

Having to create a storage object, and possibly a transaction, in order to just add some data for evaluation using the Go API is a chore, and not intuitive unless you happen to know about it. It would be great if we added a rego.Data function that would allow passing a map to populate the data object.

(There's a longer story around issues with transactions and concurrency, but I'll save that for another issue)

anderseknert avatar Jun 01 '23 10:06 anderseknert

The proposed rego.Data similar to rego.Load, rego.LoadBundle and rego.ParsedBundle would require a transaction to be passed as well. Then should be just a write call on the store as part of preparing the query.

ashutosh-narkar avatar Jun 01 '23 16:06 ashutosh-narkar

I'm using both rego.Load and rego.ParsedBundle without passing any transaction. I'm not sure I follow :)

anderseknert avatar Jun 01 '23 19:06 anderseknert

I was referring to this comment where you set the store and that this would apply to rego.Data as well.

ashutosh-narkar avatar Jun 01 '23 20:06 ashutosh-narkar

Ah, I see. Yes, that'd be the same, but the most important point here is that you shouldn't need to set the store or transactions unless you have special requirements that necessitate that, and just throwing some random data in for evaluation should not be one.

anderseknert avatar Jun 01 '23 21:06 anderseknert

But then this would make it different than rego.ParsedBundle for instance since in the rego.ParsedBundle case you'd actually write the bundle contents to the store. But that's not how you imagine rego.Data working, correct?

ashutosh-narkar avatar Jun 01 '23 21:06 ashutosh-narkar

No, I want it to be written to the store, just like when using those other helper functions 🙂

I just want to do so without the ceremony of having to provide storage and/or a transaction, just like the other helpers allow me to avoid. Example:

r := rego.New(
    rego.Query("data.example.users[0].likes"),
    rego.Data(map[string]any{"foo": "bar"}),
    rego.ParsedBundle(&b),
)

anderseknert avatar Jun 02 '23 08:06 anderseknert

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue.

stale[bot] avatar Jul 02 '23 11:07 stale[bot]

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue.

stale[bot] avatar May 09 '24 00:05 stale[bot]