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

Function groupEvaluations

pkg/attestation/renderer/chainloop/v02.go:350–399  ·  view source on GitHub ↗

groupEvaluations groups a flat list of policy evaluations by material and aggregates counters. When includeSuppressed is true the returned entries keep their suppressed violations and finding data (CAS bundle path); when false they are stripped (in-toto predicate path). Gate counters (violationsCou

(evals []*v1.PolicyEvaluation, includeSuppressed bool)

Source from the content-addressed store, hash-verified

348// exclude suppressed entries regardless of the flag — suppressedCount is
349// tracked independently.
350func groupEvaluations(evals []*v1.PolicyEvaluation, includeSuppressed bool) (*evaluationsResult, error) {
351 res := &evaluationsResult{
352 evaluations: make(map[string][]*PolicyEvaluation),
353 }
354
355 for _, p := range evals {
356 keyName := p.MaterialName
357 if keyName == "" {
358 keyName = AttPolicyEvaluation
359 }
360
361 var active, suppressed int
362 for _, vi := range p.Violations {
363 if vi.GetSuppress() {
364 suppressed++
365 } else {
366 active++
367 }
368 }
369
370 ev, err := renderEvaluation(p, includeSuppressed)
371 if err != nil {
372 return nil, err
373 }
374
375 if ev.Gate {
376 res.hasGates = true
377 }
378
379 res.suppressedCount += suppressed
380
381 switch {
382 case active > 0:
383 res.hasViolations = true
384 res.violationsCount += active
385 if ev.Gate {
386 res.hasGatedViolations = true
387 }
388 case ev.Skipped:
389 res.skippedCount++
390 default:
391 res.passedCount++
392 }
393
394 res.evaluations[keyName] = append(res.evaluations[keyName], ev)
395 }
396
397 res.evaluationsCount = len(evals)
398 return res, nil
399}
400
401func renderEvaluation(ev *v1.PolicyEvaluation, includeSuppressed bool) (*PolicyEvaluation, error) {
402 violations := make([]*PolicyViolation, 0, len(ev.Violations))

Callers 4

mappedPolicyEvaluationsFunction · 0.85

Calls 2

renderEvaluationFunction · 0.85
GetSuppressMethod · 0.45

Tested by 2