From 9e39508419325c73fb10d331f8220bdd129fefc8 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Thu, 29 Feb 2024 23:19:54 +0100 Subject: [PATCH] Return result of policy evaluation as is (don't cast) --- act/policy.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/act/policy.go b/act/policy.go index 07f2b35..92bb9f7 100644 --- a/act/policy.go +++ b/act/policy.go @@ -5,12 +5,11 @@ import ( "github.com/expr-lang/expr" "github.com/expr-lang/expr/vm" - "github.com/spf13/cast" ) type IPolicy interface { MustCompile(opts ...expr.Option) error - Eval(ctx context.Context, input Input) (bool, error) + Eval(ctx context.Context, input Input) (any, error) } type Policy struct { @@ -37,13 +36,13 @@ func (p *Policy) MustCompile(extraOpts ...expr.Option) error { return nil } -func (p *Policy) Eval(ctx context.Context, input Input) (bool, error) { +func (p *Policy) Eval(ctx context.Context, input Input) (any, error) { output, err := expr.Run(p.prg, input) if err != nil { return false, err } - return cast.ToBool(output), nil + return output, nil } func MustNewPolicy(