MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / policiesTable

Function policiesTable

app/cli/cmd/workflow_workflow_run_describe.go:254–302  ·  view source on GitHub ↗
(evs []*action.PolicyEvaluation, mt table.Writer, debugMode bool)

Source from the content-addressed store, hash-verified

252}
253
254func policiesTable(evs []*action.PolicyEvaluation, mt table.Writer, debugMode bool) {
255 for _, ev := range evs {
256 msg := ""
257
258 switch {
259 case ev.Skipped:
260 switch {
261 case len(ev.SkipReasons) == 1:
262 msg = text.Colors{text.FgHiYellow}.Sprintf("skipped - %s", ev.SkipReasons[0])
263 case debugMode:
264 msg = text.Colors{text.FgHiYellow}.Sprintf("skipped - multiple reasons:\n - %s",
265 strings.Join(ev.SkipReasons, "\n - "))
266 default:
267 msg = text.Colors{text.FgHiYellow}.Sprint("the policy was skipped in all execution paths")
268 }
269 case len(ev.Violations) == 0:
270 msg = text.Colors{text.FgHiGreen}.Sprint("Ok")
271 default:
272 hasActive := false
273 lines := make([]string, 0, len(ev.Violations))
274 for _, v := range ev.Violations {
275 color := text.FgHiRed
276 if v.Suppress {
277 color = text.FgHiYellow
278 } else {
279 hasActive = true
280 }
281 lines = append(lines, text.Colors{color}.Sprint(violationSummary(v)))
282 }
283 // When every finding is suppressed the gate passed; lead with
284 // "Ok" so the row carries the same signal as the no-violations
285 // case rather than reading like a failure.
286 switch {
287 case !hasActive:
288 msg = text.Colors{text.FgHiGreen}.Sprint("Ok") + "\n - " + strings.Join(lines, "\n - ")
289 case len(lines) == 1:
290 msg = lines[0]
291 default:
292 msg = "\n - " + strings.Join(lines, "\n - ")
293 }
294 }
295
296 name := ev.Name
297 if ev.Gate {
298 name = fmt.Sprintf("%s (gate)", ev.Name)
299 }
300 mt.AppendRow(table.Row{"", fmt.Sprintf("%s: %s", name, msg)})
301 }
302}
303
304// violationSummary builds a single-line description of a violation using the
305// structured finding when present (CVE id + severity + package + fix info,

Callers 5

predicateV1TableFunction · 0.85
appendMaterialRowsFunction · 0.85
displayMaterialInfoFunction · 0.85

Calls 1

violationSummaryFunction · 0.85

Tested by

no test coverage detected