Skip to content

Commit

Permalink
feat(cli): show skipped policies (#1707)
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
  • Loading branch information
migmartri authored Jan 8, 2025
1 parent 3e83aa4 commit 86a1cac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
16 changes: 8 additions & 8 deletions app/cli/cmd/attestation_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ func attestationStatusTableOutput(status *action.AttestationStatusResult, full b
}
}

var blockingColor text.Color
var blockingText = "ADVISORY"
if status.MustBlockOnPolicyViolations {
blockingColor = text.FgHiYellow
blockingText = "ENFORCED"
}
gt.AppendRow(table.Row{"Policy violation strategy", blockingColor.Sprint(blockingText)})

evs := status.PolicyEvaluations[chainloop.AttPolicyEvaluation]
if len(evs) > 0 {
var blockingColor text.Color
var blockingText = "ADVISORY"
if status.MustBlockOnPolicyViolations {
blockingColor = text.FgHiYellow
blockingText = "ENFORCED"
}

gt.AppendRow(table.Row{"Policy violation strategy", blockingColor.Sprint(blockingText)})
gt.AppendRow(table.Row{"Policies", "------"})
policiesTable(evs, gt)
}
Expand Down
30 changes: 18 additions & 12 deletions app/cli/cmd/workflow_workflow_run_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,28 +231,34 @@ func predicateV1Table(att *action.WorkflowRunAttestationItem) {

func policiesTable(evs []*action.PolicyEvaluation, mt table.Writer) {
for _, ev := range evs {
color := text.Colors{text.FgHiRed}
var violations []string
var prefix = ""
if len(ev.Violations) > 0 {
msg := ""

switch {
case ev.Skipped:
msg = text.Colors{text.FgHiYellow}.Sprintf("skipped - %s", strings.Join(ev.SkipReasons, ", "))
case len(ev.Violations) == 0:
msg = text.Colors{text.FgHiGreen}.Sprint("Ok")
case len(ev.Violations) > 0:
color := text.Colors{text.FgHiRed}
var violations []string
var prefix = ""
for _, v := range ev.Violations {
violations = append(violations, v.Message)
}
// For multiple violations, we want to indent the list
if len(violations) > 1 {
prefix = "\n - "
}
} else {
violations = append(violations, "Ok")
color = text.Colors{text.FgHiGreen}
}

// Color the violations text before joining
for i, v := range violations {
violations[i] = color.Sprint(v)
// Color the violations text before joining
for i, v := range violations {
violations[i] = color.Sprint(v)
}

msg = strings.Join(violations, prefix)
}

mt.AppendRow(table.Row{"", fmt.Sprintf("%s: %s", ev.Name, prefix+strings.Join(violations, prefix))})
mt.AppendRow(table.Row{"", fmt.Sprintf("%s: %s", ev.Name, msg)})
}
}

Expand Down

0 comments on commit 86a1cac

Please sign in to comment.