getPolicyEvaluations retrieves both material-level and attestation-level policy evaluations and returns if it has violations
(c *crafter.Crafter)
| 181 | |
| 182 | // getPolicyEvaluations retrieves both material-level and attestation-level policy evaluations and returns if it has violations |
| 183 | func 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) |
no test coverage detected