diff --git a/pkg/cmd/attestation/io/handler.go b/pkg/cmd/attestation/io/handler.go index 167128a42..1e5114040 100644 --- a/pkg/cmd/attestation/io/handler.go +++ b/pkg/cmd/attestation/io/handler.go @@ -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 diff --git a/pkg/cmd/attestation/verify/verify.go b/pkg/cmd/attestation/verify/verify.go index 7b6250c0c..73689a1b8 100644 --- a/pkg/cmd/attestation/verify/verify.go +++ b/pkg/cmd/attestation/verify/verify.go @@ -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