rego4k docs
I want to
- Evaluate a policy in my Kotlin service: Make an engine, then the forms of a result.
- Load policies from a directory: Compile the modules.
- Load a bundle: Read and compile a bundle.
- Convert JSON from a JSON library to the input of a query: From JSON.
- Convert Kotlin data to a value: From Kotlin data.
- Use the regex semantics of OPA (RE2): The differences.
- Sign each decision, and verify it with cosign: Sign a decision, then Verify and reproduce a decision.
- Step through a policy in the browser: Run the debugger alone.
- Shrink a bundle to the rules of its entrypoints: Tree shaking.
- Run my Rego tests in JUnit: In JUnit.
- Test
http.sendwith no network:http.sendin a test. - Add a builtin of my own: A builtin of your own.
- Host policies on a decision server: The hosted bundles.
- Replace the
opacommand line: Run it. - Replace a part of the engine: Replace a part.
- Decorate a part of the engine: Decorate a part.
The code on these pages
Each block of Kotlin and Rego on these pages is a part of a program in
site/examples. The generator of the site reads the lines between // example <name> and
// example end from the program. Below each block, a link goes to these lines on GitHub. A test runs each program
and examines its result, in each build. Thus a page cannot show code that does not compile, or code that gives another
result. A test of the site fails if a page of the docs has a block of Kotlin or Rego that is not from site/examples.
The programs read the policy of the guides, authz.rego. An admin can do anything, and a viewer can read:
package authz
default allow := false
allow if "admin" in input.user.roles
allow if {
input.method == "GET"
"viewer" in input.user.roles
}
reasons contains "the user is not an admin" if not "admin" in input.user.rolesauthz.rego, lines 2 to 13, on GitHubThe sections
| Section | Content |
|---|---|
| Modules | Each module: what it does, its Maven coordinates, its dependencies and its README. |
| Rego and its parts | The engine, its parser, compiler, evaluator and cache, and how to replace or decorate each part. |
| Values and conversion | The documents as Values, and their conversion from Kotlin data and JSON. |
| Queries and results | allowed, eval, query, prepare and result, errors, and the trace of a query. |
| Builtins | The sets of builtins, the three kinds, and builtins of your own. |
| Bundles | Read, compile and write a bundle, tree shaking, and signed bundles. |
| Tests of Rego | TestRunner, the report of opa test, JUnit, and http.send in a test. |
| The decision server | DecisionServer, its modules, the hosted bundles and Mount. |
| Signed decisions and inputs | Sign a decision, verify it, reproduce it, and sign an input. |
| The debugger | The debugger alone, on your pages, and on the decision server. |
| The command line | rego4k and the commands of opa, and a command line with your own builtins. |
| OPA and rego4k | The capabilities of OPA as interfaces, and the differences from OPA. |
The README of each module has the details of the module, for example its packages, its tests and its dependencies. Modules lists them.