Skip to content

Commit 62670e8

Browse files
authored
chore(policies): add policies to table output (#1131)
Signed-off-by: Jose I. Paris <[email protected]>
1 parent f9f5e06 commit 62670e8

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

app/cli/cmd/workflow_workflow_run_describe.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ import (
2121
"fmt"
2222
"io"
2323
"os"
24+
"strings"
2425
"time"
2526

2627
"github.com/chainloop-dev/chainloop/app/cli/internal/action"
28+
v1 "github.com/chainloop-dev/chainloop/internal/attestation/crafter/api/attestation/v1"
29+
"github.com/chainloop-dev/chainloop/internal/attestation/renderer"
2730
"github.com/jedib0t/go-pretty/v6/table"
2831
"github.com/jedib0t/go-pretty/v6/text"
2932
"github.com/muesli/reflow/wrap"
@@ -193,6 +196,12 @@ func predicateV1Table(att *action.WorkflowRunAttestationItem) {
193196
mt.AppendRow(table.Row{"", fmt.Sprintf("%s: %s", a.Name, a.Value)})
194197
}
195198
}
199+
evs := att.PolicyEvaluations[m.Name].GetEvaluations()
200+
if len(evs) > 0 {
201+
mt.AppendSeparator()
202+
mt.AppendRow(table.Row{"Policies"})
203+
policiesTable(evs, mt)
204+
}
196205
mt.AppendSeparator()
197206
}
198207

@@ -211,6 +220,30 @@ func predicateV1Table(att *action.WorkflowRunAttestationItem) {
211220
}
212221
mt.Render()
213222
}
223+
224+
evs := att.PolicyEvaluations[renderer.AttPolicyEvaluation].GetEvaluations()
225+
if len(evs) > 0 {
226+
mt := newTableWriter()
227+
mt.SetTitle("Attestation policies")
228+
policiesTable(evs, mt)
229+
mt.Render()
230+
}
231+
}
232+
233+
func policiesTable(evs []*v1.PolicyEvaluation, mt table.Writer) {
234+
for _, ev := range evs {
235+
mt.AppendSeparator()
236+
mt.AppendRow(table.Row{"Policy", ev.Name})
237+
var violations []string
238+
if len(ev.Violations) > 0 {
239+
for _, v := range ev.Violations {
240+
violations = append(violations, v.Message)
241+
}
242+
} else {
243+
violations = append(violations, "None")
244+
}
245+
mt.AppendRow(table.Row{"Violations", fmt.Sprint(strings.Join(violations, "\n"))})
246+
}
214247
}
215248

216249
func encodeAttestationOutput(run *action.WorkflowRunItemFull, writer io.Writer) error {

0 commit comments

Comments
 (0)