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

Function getPolicyEvaluations

app/cli/pkg/action/attestation_status.go:183–207  ·  view source on GitHub ↗

getPolicyEvaluations retrieves both material-level and attestation-level policy evaluations and returns if it has violations

(c *crafter.Crafter)

Source from the content-addressed store, hash-verified

181
182// getPolicyEvaluations retrieves both material-level and attestation-level policy evaluations and returns if it has violations
183func getPolicyEvaluations(c *crafter.Crafter) (map[string][]*PolicyEvaluation, bool) {
184 // grouped by material name
185 evaluations := make(map[string][]*PolicyEvaluation)
186 var hasViolations bool
187
188 // map evaluations
189 for _, v := range c.CraftingState.Attestation.GetPolicyEvaluations() {
190 keyName := v.MaterialName
191 if keyName == "" {
192 keyName = chainloop.AttPolicyEvaluation
193 }
194
195 if len(v.GetViolations()) > 0 {
196 hasViolations = true
197 }
198
199 if existing, ok := evaluations[keyName]; ok {
200 evaluations[keyName] = append(existing, policyEvaluationStateToActionForStatus(v))
201 } else {
202 evaluations[keyName] = []*PolicyEvaluation{policyEvaluationStateToActionForStatus(v)}
203 }
204 }
205
206 return evaluations, hasViolations
207}
208
209// populateMaterials populates the materials in the attestation result regardless of where they are defined
210// (contract schema or inline in the attestation)

Callers 3

RunMethod · 0.85
RunMethod · 0.85
GetPolicyEvaluationsMethod · 0.85

Calls 3

GetPolicyEvaluationsMethod · 0.65
GetViolationsMethod · 0.45

Tested by

no test coverage detected