forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rego+topdown: allow custom builtins via rego pkg to halt
Before, functions provided via arguments to `rego.New()` hadn't been able to halt the topdown evaluation. Now, they do, if they return a `*rego.HaltError`. Fixes open-policy-agent#3534. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
- Loading branch information
Showing
4 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package rego | ||
|
||
// HaltError is an error type to return from a custom function implementation | ||
// that will abort the evaluation process (analogous to topdown.Halt). | ||
type HaltError struct { | ||
err error | ||
} | ||
|
||
// Error delegates to the wrapped error | ||
func (h *HaltError) Error() string { | ||
return h.err.Error() | ||
} | ||
|
||
// NewHaltError wraps an error such that the evaluation process will stop | ||
// when it occurs. | ||
func NewHaltError(err error) error { | ||
return &HaltError{err: err} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters