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

simplify the regorus API #36

Closed
eric-therond opened this issue Nov 5, 2023 · 7 comments · Fixed by #38
Closed

simplify the regorus API #36

eric-therond opened this issue Nov 5, 2023 · 7 comments · Fixed by #38

Comments

@eric-therond
Copy link
Contributor

Hello
I am facing troubles integrating regorus into an existing project mainly because of references to modules/schedule in the interpreter.

Because of this and the modules/schedule lifetimes I need to refactor my project to call the regorus API (like in test cases) and then to have a reference to the interpreter that is passed through functions of my project that need it (instead of storing the interpreter instance into a struct).

What do you think about "to hide" the complexity of the API (create the Sources, Parse and Analyze them, ...) and to store everything (struct instances not references) into the interpreter? something like that:

let mut interpreter = interpreter::Interpreter::new();
interpreter.add_module("myfile.rego");
interpreter.add_input("foo.json");
interpreter.eval_modules(enable_tracing)?;
@anakrish
Copy link
Collaborator

anakrish commented Nov 6, 2023

Great idea. Do you want to take a stab at it?

@eric-therond
Copy link
Contributor Author

I tried a bit and the first part (storing modules, schedule, source objects in the struct interpreter...) requires a lot of changes in the whole code base and it's beyond my skills for the moment.

@anakrish anakrish mentioned this issue Nov 8, 2023
@anakrish
Copy link
Collaborator

anakrish commented Nov 8, 2023

I've taken a pass at simplifying the API:

let mut engine = regorus::Engine::new();
.

Note, there are opportunities for optimizations and refactor/simplification/cleanup. The API will change in future.

@anakrish
Copy link
Collaborator

#43 does away with lifetimes. This will also allow holding on to various objects.

Note: The API is not finalized yet.

@anakrish
Copy link
Collaborator

@eric-therond
Can you share your use-case? IIRC you explicitly call eval_rule.

@eric-therond
Copy link
Contributor Author

eric-therond commented Mar 15, 2024

@anakrish

  1. At the beginning of the program, I parse and "compile" all the rego rules.
  2. Then the program evaluates the rego rules (eval_rule) that are associated to group of target files (*.yaml => rego(rule1, rule2, rule3), *.json=> rego(rule4, rule5, rule6) ...).
  3. In reality it's a bit more complex eval_rule can be trigerred depending on some "events".

I suppose I have to use eval_query? I tried in the past, I don't remember why I was not able to continue in this direction. I will try again and update this thread.

@anakrish
Copy link
Collaborator

Thank you. Do let me know how it turns out. I want to make the Engine API support your use case nicely as well.

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

Successfully merging a pull request may close this issue.

2 participants