diff options
| author | mo khan <mo@mokhan.ca> | 2025-04-02 10:35:00 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-04-02 10:35:00 -0600 |
| commit | ea825411089e2ab2bcb629bc4967e71a23f36edd (patch) | |
| tree | 7d6b97f305047e2eaebb368c584e67961bd67c09 | |
| parent | 60b090e16fdd0f65e7be40ade81cae7ab818b0ea (diff) | |
refactor: use xlog to log diagnostic data
| -rw-r--r-- | pkg/policies/init.go | 13 |
1 files changed, 10 insertions, 3 deletions
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 } |
