Skip to content

Commit

Permalink
Add support for printing rego messages on CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mizutani committed Jan 15, 2024
1 parent 681c188 commit c029c28
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/chain/core/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package core

import (
"errors"
"fmt"

"log/slog"

Expand Down Expand Up @@ -51,11 +52,15 @@ func (x *Core) QueryActionPolicy(ctx *model.Context, in, out any) error {

func makeRegoPrint(ctx *model.Context) policy.RegoPrint {
return func(file string, row int, msg string) error {
ctx.Logger().Info("rego print",
slog.String("file", file),
slog.Int("row", row),
slog.String("msg", msg),
)
if ctx.OnCLI() {
fmt.Printf(" %s:%d: %s\n", file, row, msg)
} else {
ctx.Logger().Info("rego print",
slog.String("file", file),
slog.Int("row", row),
slog.String("msg", msg),
)
}
return nil
}
}
1 change: 1 addition & 0 deletions pkg/controller/cli/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func cmdPlay() *cli.Command {

ctx := model.NewContext(
model.WithBase(c.Context),
model.WithCLI(),
)
ctx.Logger().Info("starting alertchain with play mode", slog.Any("playbook", playbookPath))

Expand Down

0 comments on commit c029c28

Please sign in to comment.