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

internal/eval: remove the inCache #45

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ const (
// IsAuthorized uses the combination of the PolicySet and Entities to determine
// if the given Request to determine Decision and Diagnostic.
func (p PolicySet) IsAuthorized(entityMap Entities, req Request) (Decision, Diagnostic) {
c := eval.InitEnv(&eval.Env{
env := eval.Env{
Entities: entityMap,
Principal: req.Principal,
Action: req.Action,
Resource: req.Resource,
Context: req.Context,
})
}
var diag Diagnostic
var forbids []DiagnosticReason
var permits []DiagnosticReason
Expand All @@ -35,7 +35,7 @@ func (p PolicySet) IsAuthorized(entityMap Entities, req Request) (Decision, Diag
// - For permit, all permits must be run to collect annotations
// - For forbid, forbids must be run to collect annotations
for id, po := range p.policies {
result, err := po.eval.Eval(c)
result, err := po.eval.Eval(env)
apg marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
diag.Errors = append(diag.Errors, DiagnosticError{PolicyID: id, Position: po.Position(), Message: err.Error()})
continue
Expand Down
2 changes: 1 addition & 1 deletion internal/eval/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type BoolEvaler struct {
eval Evaler
}

func (e *BoolEvaler) Eval(env *Env) (types.Boolean, error) {
func (e *BoolEvaler) Eval(env Env) (types.Boolean, error) {
v, err := e.eval.Eval(env)
if err != nil {
return false, err
Expand Down
8 changes: 4 additions & 4 deletions internal/eval/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestCompile(t *testing.T) {
t.Parallel()
e := Compile(ast.Permit())
res, err := e.Eval(nil)
res, err := e.Eval(Env{})
testutil.OK(t, err)
testutil.Equals(t, res, types.True)
}
Expand All @@ -22,7 +22,7 @@ func TestBoolEvaler(t *testing.T) {
t.Run("Happy", func(t *testing.T) {
t.Parallel()
b := BoolEvaler{eval: newLiteralEval(types.True)}
v, err := b.Eval(nil)
v, err := b.Eval(Env{})
testutil.OK(t, err)
testutil.Equals(t, v, true)
})
Expand All @@ -31,15 +31,15 @@ func TestBoolEvaler(t *testing.T) {
t.Parallel()
errWant := fmt.Errorf("error")
b := BoolEvaler{eval: newErrorEval(errWant)}
v, err := b.Eval(nil)
v, err := b.Eval(Env{})
testutil.ErrorIs(t, err, errWant)
testutil.Equals(t, v, false)
})

t.Run("NonBool", func(t *testing.T) {
t.Parallel()
b := BoolEvaler{eval: newLiteralEval(types.String("bad"))}
v, err := b.Eval(nil)
v, err := b.Eval(Env{})
testutil.ErrorIs(t, err, ErrType)
testutil.Equals(t, v, false)
})
Expand Down
4 changes: 2 additions & 2 deletions internal/eval/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ func TestToEval(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
e := toEval(tt.in.AsIsNode())
out, err := e.Eval(InitEnv(&Env{
out, err := e.Eval(Env{
Principal: types.NewEntityUID("Actor", "principal"),
Action: types.NewEntityUID("Action", "test"),
Resource: types.NewEntityUID("Resource", "database"),
Context: types.Record{},
}))
})
tt.err(t, err)
testutil.Equals(t, out, tt.out)
})
Expand Down
Loading
Loading