From ea825411089e2ab2bcb629bc4967e71a23f36edd Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 2 Apr 2025 10:35:00 -0600 Subject: refactor: use xlog to log diagnostic data --- pkg/policies/init.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'pkg/policies') diff --git a/pkg/policies/init.go b/pkg/policies/init.go index 9916b11..d455cb8 100644 --- a/pkg/policies/init.go +++ b/pkg/policies/init.go @@ -4,13 +4,13 @@ import ( "embed" _ "embed" "encoding/json" - "fmt" "io/fs" "log" "github.com/cedar-policy/cedar-go" "github.com/cedar-policy/cedar-go/types" "github.com/xlgmokha/x/pkg/x" + xlog "gitlab.com/mokhax/spike/pkg/log" ) //go:embed *.cedar @@ -65,8 +65,15 @@ func Allowed(request cedar.Request) bool { x.Check(json.Unmarshal([]byte(entitiesJSON), &entities)) ok, diagnostic := All.IsAuthorized(entities, request) - if len(diagnostic.Errors) > 0 || len(diagnostic.Reasons) > 0 { - fmt.Printf("%v %v\n", diagnostic.Errors, diagnostic.Reasons) + if len(diagnostic.Errors) > 0 { + for err := range diagnostic.Errors { + xlog.Default.Printf("%v\n", err) + } + } + if len(diagnostic.Reasons) > 0 { + for reason := range diagnostic.Reasons { + xlog.Default.Printf("%v\n", reason) + } } return ok == types.Allow } -- cgit v1.2.3