Skip to content

Commit 86a1cac

Browse files
authored
feat(cli): show skipped policies (#1707)
Signed-off-by: Miguel Martinez <[email protected]>
1 parent 3e83aa4 commit 86a1cac

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

app/cli/cmd/attestation_status.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ func attestationStatusTableOutput(status *action.AttestationStatusResult, full b
113113
}
114114
}
115115

116+
var blockingColor text.Color
117+
var blockingText = "ADVISORY"
118+
if status.MustBlockOnPolicyViolations {
119+
blockingColor = text.FgHiYellow
120+
blockingText = "ENFORCED"
121+
}
122+
gt.AppendRow(table.Row{"Policy violation strategy", blockingColor.Sprint(blockingText)})
123+
116124
evs := status.PolicyEvaluations[chainloop.AttPolicyEvaluation]
117125
if len(evs) > 0 {
118-
var blockingColor text.Color
119-
var blockingText = "ADVISORY"
120-
if status.MustBlockOnPolicyViolations {
121-
blockingColor = text.FgHiYellow
122-
blockingText = "ENFORCED"
123-
}
124-
125-
gt.AppendRow(table.Row{"Policy violation strategy", blockingColor.Sprint(blockingText)})
126126
gt.AppendRow(table.Row{"Policies", "------"})
127127
policiesTable(evs, gt)
128128
}

app/cli/cmd/workflow_workflow_run_describe.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,28 +231,34 @@ func predicateV1Table(att *action.WorkflowRunAttestationItem) {
231231

232232
func policiesTable(evs []*action.PolicyEvaluation, mt table.Writer) {
233233
for _, ev := range evs {
234-
color := text.Colors{text.FgHiRed}
235-
var violations []string
236-
var prefix = ""
237-
if len(ev.Violations) > 0 {
234+
msg := ""
235+
236+
switch {
237+
case ev.Skipped:
238+
msg = text.Colors{text.FgHiYellow}.Sprintf("skipped - %s", strings.Join(ev.SkipReasons, ", "))
239+
case len(ev.Violations) == 0:
240+
msg = text.Colors{text.FgHiGreen}.Sprint("Ok")
241+
case len(ev.Violations) > 0:
242+
color := text.Colors{text.FgHiRed}
243+
var violations []string
244+
var prefix = ""
238245
for _, v := range ev.Violations {
239246
violations = append(violations, v.Message)
240247
}
241248
// For multiple violations, we want to indent the list
242249
if len(violations) > 1 {
243250
prefix = "\n - "
244251
}
245-
} else {
246-
violations = append(violations, "Ok")
247-
color = text.Colors{text.FgHiGreen}
248-
}
249252

250-
// Color the violations text before joining
251-
for i, v := range violations {
252-
violations[i] = color.Sprint(v)
253+
// Color the violations text before joining
254+
for i, v := range violations {
255+
violations[i] = color.Sprint(v)
256+
}
257+
258+
msg = strings.Join(violations, prefix)
253259
}
254260

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

0 commit comments

Comments
 (0)