@@ -56,7 +56,7 @@ type WorkflowRunAttestationItem struct {
5656 // Digest in CAS backend
5757 Digest string `json:"digest"`
5858 // Policy violations
59- PolicyEvaluations map [string ]* pb. PolicyEvaluations `json:"policy_evaluations,omitempty"`
59+ PolicyEvaluations map [string ][] * PolicyEvaluation `json:"policy_evaluations,omitempty"`
6060}
6161
6262type Material struct {
@@ -81,6 +81,28 @@ type Annotation struct {
8181 Value string `json:"value"`
8282}
8383
84+ type PolicyEvaluation struct {
85+ Name string `json:"name"`
86+ MaterialName string `json:"material_name,omitempty"`
87+ Body string `json:"body,omitempty"`
88+ Description string `json:"description,omitempty"`
89+ Annotations map [string ]string `json:"annotations,omitempty"`
90+ Violations []* PolicyViolation `json:"violations,omitempty"`
91+ PolicyReference * PolicyReference `json:"policy_reference,omitempty"`
92+ With map [string ]string `json:"with,omitempty"`
93+ Type string `json:"type"`
94+ }
95+
96+ type PolicyViolation struct {
97+ Subject string `json:"subject"`
98+ Message string `json:"message"`
99+ }
100+
101+ type PolicyReference struct {
102+ Name string `json:"name"`
103+ Digest map [string ]string `json:"digest"`
104+ }
105+
84106func (i * WorkflowRunAttestationItem ) Statement () * intoto.Statement {
85107 return i .statement
86108}
@@ -171,19 +193,56 @@ func (action *WorkflowRunDescribe) Run(ctx context.Context, opts *WorkflowRunDes
171193 })
172194 }
173195
196+ evaluations := make (map [string ][]* PolicyEvaluation )
197+ for k , v := range attestation .GetPolicyEvaluations () {
198+ evs := make ([]* PolicyEvaluation , 0 )
199+ for _ , ev := range v .Evaluations {
200+ evs = append (evs , policyEvaluationPBToAction (ev ))
201+ }
202+ evaluations [k ] = evs
203+ }
204+
174205 item .Attestation = & WorkflowRunAttestationItem {
175206 Envelope : envelope ,
176207 statement : statement ,
177208 EnvVars : envVars ,
178209 Materials : materials ,
179210 Annotations : annotations ,
180211 Digest : attestation .DigestInCasBackend ,
181- PolicyEvaluations : attestation . PolicyEvaluations ,
212+ PolicyEvaluations : evaluations ,
182213 }
183214
184215 return item , nil
185216}
186217
218+ func policyEvaluationPBToAction (in * pb.PolicyEvaluation ) * PolicyEvaluation {
219+ var pr * PolicyReference
220+ if in .PolicyReference != nil {
221+ pr = & PolicyReference {
222+ Name : in .PolicyReference .Name ,
223+ Digest : in .PolicyReference .Digest ,
224+ }
225+ }
226+ violations := make ([]* PolicyViolation , 0 , len (in .Violations ))
227+ for _ , v := range in .Violations {
228+ violations = append (violations , & PolicyViolation {
229+ Subject : v .Subject ,
230+ Message : v .Message ,
231+ })
232+ }
233+ return & PolicyEvaluation {
234+ Name : in .Name ,
235+ MaterialName : in .MaterialName ,
236+ Body : in .Body ,
237+ Description : in .Description ,
238+ Annotations : in .Annotations ,
239+ With : in .With ,
240+ Type : in .Type ,
241+ PolicyReference : pr ,
242+ Violations : violations ,
243+ }
244+ }
245+
187246func materialPBToAction (in * pb.AttestationItem_Material ) * Material {
188247 m := & Material {
189248 Name : in .Name ,
0 commit comments