print attestation output info as bullet points instead of table
Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
parent
2ddfe865f4
commit
2ffce8ae9f
2 changed files with 34 additions and 9 deletions
|
|
@ -2,6 +2,7 @@ package io
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cli/cli/v2/internal/tableprinter"
|
||||
"github.com/cli/cli/v2/pkg/iostreams"
|
||||
|
|
@ -65,10 +66,25 @@ func (h *Handler) VerbosePrintf(f string, v ...interface{}) (int, error) {
|
|||
if !h.debugEnabled || !h.IO.IsStdoutTTY() {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
return fmt.Fprintf(h.IO.ErrOut, f, v...)
|
||||
}
|
||||
|
||||
func (h *Handler) PrintBulletPoints(rows [][]string) (int, error) {
|
||||
maxColLen := 0
|
||||
for _, row := range rows {
|
||||
if len(row[0]) > maxColLen {
|
||||
maxColLen = len(row[0])
|
||||
}
|
||||
}
|
||||
|
||||
info := ""
|
||||
for _, row := range rows {
|
||||
dots := strings.Repeat(".", maxColLen-len(row[0]))
|
||||
info += fmt.Sprintf("%s:%s %s\n", row[0], dots, row[1])
|
||||
}
|
||||
return fmt.Fprintln(h.IO.ErrOut, info)
|
||||
}
|
||||
|
||||
func (h *Handler) PrintTable(headers []string, rows [][]string) error {
|
||||
if !h.IO.IsStdoutTTY() {
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -262,20 +262,29 @@ func runVerify(opts *Options) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
opts.Logger.Printf("The following %d %s matched the policy criteria:\n\n", len(verified), text.Pluralize(len(verified), "attestation"))
|
||||
opts.Logger.Printf("%s matched the policy criteria:\n", text.Pluralize(len(verified), "attestation"))
|
||||
|
||||
// Otherwise print the results to the terminal in a table
|
||||
tableContent, err := buildTableVerifyContent(opts.Tenant, verified)
|
||||
// Otherwise print the results to the terminal
|
||||
buildConfigURI := verified[0].VerificationResult.Signature.Certificate.Extensions.BuildConfigURI
|
||||
sourceRepoAndOrg, sourceWorkflow, err := extractAttestationDetail(opts.Tenant, buildConfigURI)
|
||||
if err != nil {
|
||||
opts.Logger.Println(opts.Logger.ColorScheme.Red("failed to parse results"))
|
||||
opts.Logger.Println(opts.Logger.ColorScheme.Red("failed to parse build config URI"))
|
||||
return err
|
||||
}
|
||||
builderSignerURI := verified[0].VerificationResult.Signature.Certificate.Extensions.BuildSignerURI
|
||||
signerRepoAndOrg, signerWorkflow, err := extractAttestationDetail(opts.Tenant, builderSignerURI)
|
||||
if err != nil {
|
||||
opts.Logger.Println(opts.Logger.ColorScheme.Red("failed to parse build signer URI"))
|
||||
return err
|
||||
}
|
||||
|
||||
headers := []string{"signer repo", "signer workflow", "builder repo", "builder workflow"}
|
||||
if err = opts.Logger.PrintTable(headers, tableContent); err != nil {
|
||||
opts.Logger.Println(opts.Logger.ColorScheme.Red("failed to print attestation details to table"))
|
||||
return err
|
||||
rows := [][]string{
|
||||
[]string{"- Build repo", sourceRepoAndOrg},
|
||||
[]string{"- Build workflow", sourceWorkflow},
|
||||
[]string{"- Signer repo", signerRepoAndOrg},
|
||||
[]string{"- Signer workflow", signerWorkflow},
|
||||
}
|
||||
opts.Logger.PrintBulletPoints(rows)
|
||||
|
||||
// All attestations passed verification and policy evaluation
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue