@@ -43,7 +43,7 @@ type EvalResult struct {
43
43
Ignored bool
44
44
}
45
45
46
- func Evaluate (opts * EvalOptions , logger zerolog.Logger ) (* EvalResult , error ) {
46
+ func Evaluate (opts * EvalOptions , logger zerolog.Logger ) ([] * EvalResult , error ) {
47
47
// 1. Create crafting schema
48
48
schema , err := createCraftingSchema (opts .PolicyPath , opts .Inputs )
49
49
if err != nil {
@@ -81,36 +81,44 @@ func createCraftingSchema(policyPath string, inputs map[string]string) (*v1.Craf
81
81
}, nil
82
82
}
83
83
84
- func verifyMaterial (schema * v1.CraftingSchema , material * v12.Attestation_Material , materialPath string , logger * zerolog.Logger ) (* EvalResult , error ) {
84
+ func verifyMaterial (schema * v1.CraftingSchema , material * v12.Attestation_Material , materialPath string , logger * zerolog.Logger ) ([] * EvalResult , error ) {
85
85
v := policies .NewPolicyVerifier (schema , nil , logger )
86
- evs , err := v .VerifyMaterial (context .Background (), material , materialPath )
86
+ policyEvs , err := v .VerifyMaterial (context .Background (), material , materialPath )
87
87
if err != nil {
88
88
return nil , err
89
89
}
90
90
91
- result := & EvalResult {
92
- Skipped : false ,
93
- SkipReasons : []string {},
94
- Violations : []string {},
95
- Ignored : true ,
96
- }
97
-
98
- if len (evs ) == 0 {
99
- return result , nil
91
+ // no evaluations were returned
92
+ if len (policyEvs ) == 0 {
93
+ return []* EvalResult {
94
+ {
95
+ Ignored : true ,
96
+ Skipped : false ,
97
+ SkipReasons : []string {},
98
+ Violations : []string {},
99
+ },
100
+ }, nil
100
101
}
101
102
102
- result .Ignored = false
103
- result .Skipped = evs [0 ].GetSkipped ()
104
- result .SkipReasons = evs [0 ].SkipReasons
105
- result .Violations = make ([]string , 0 , len (evs [0 ].Violations ))
103
+ results := make ([]* EvalResult , 0 , len (policyEvs ))
104
+ for _ , policyEv := range policyEvs {
105
+ result := & EvalResult {
106
+ Skipped : policyEv .GetSkipped (),
107
+ SkipReasons : policyEv .SkipReasons ,
108
+ Ignored : false ,
109
+ }
106
110
107
- for _ , e := range evs {
108
- for _ , v := range e .Violations {
109
- result .Violations = append (result .Violations , fmt .Sprintf ("%s: %s" , v .Subject , v .Message ))
111
+ // Collect all violation messages
112
+ violations := make ([]string , 0 , len (policyEv .Violations ))
113
+ for _ , v := range policyEv .Violations {
114
+ violations = append (violations , v .Message )
110
115
}
116
+ result .Violations = violations
117
+
118
+ results = append (results , result )
111
119
}
112
120
113
- return result , nil
121
+ return results , nil
114
122
}
115
123
116
124
func craftMaterial (materialPath , materialKind string , logger * zerolog.Logger ) (* v12.Attestation_Material , error ) {
0 commit comments