Skip to content

Commit

Permalink
change how table is constructed, and check for nil values
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristofferNissen committed Oct 29, 2024
1 parent f90ebb9 commit cca4bf6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
21 changes: 10 additions & 11 deletions pkg/cosign/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,21 @@ func (vo *VerifyOption) Run(ctx context.Context) (map[*registry.Registry]map[*im
row := rows[ref]
if row == nil {
row = to.Ptr(table.Row{sc.Value("index_import"), ref})
rows[ref] = row
keys = append(keys, ref)
}

if b || vo.VerifyExisting {

name, err := i.ImageName()
if err != nil {
return nil, err
}
if r.PrefixSource {
old := name
name, _ = image.UpdateNameWithPrefixSource(i)
name, err = image.UpdateNameWithPrefixSource(i)
if err != nil {
return nil, err
}
slog.Info("registry has PrefixSource enabled", slog.String("old", old), slog.String("new", name))
}

Expand Down Expand Up @@ -195,31 +198,27 @@ func (vo *VerifyOption) Run(ctx context.Context) (map[*registry.Registry]map[*im
fallthrough
case isImageWithoutSignatureErr(err):
elem[i] = true
_ = bar.Add(1)
*row = append(*row, terminal.StatusEmoji(false))
sc.Inc("index_import")
continue
default:
return make(map[*registry.Registry]map[*image.Image]bool), err
}
}

elem[i] = false
*row = append(*row, terminal.StatusEmoji(true))

*row = append(*row, terminal.StatusEmoji(!elem[i]))
sc.Inc("index_import")
_ = bar.Add(1)
}

rows[ref] = row

}
m[r] = elem
}

// Output table
for _, k := range keys {
vo.Report.AddRow(*rows[k])
valP := rows[k]
if valP != nil {
vo.Report.AddRow(*valP)
}
}
vo.Report.AddHeader(header)

Expand Down
15 changes: 6 additions & 9 deletions pkg/cosign/verifyChart.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ func (vo *VerifyChartOption) Run(ctx context.Context) (map[*registry.Registry]ma
row := rows[c.Name]
if row == nil {
row = to.Ptr(table.Row{sc.Value("index_sign_charts"), fmt.Sprintf("charts/%s", c.Name), c.Version})
rows[c.Name] = row
keys = append(keys, c.Name)
}

if b || vo.VerifyExisting {

name := fmt.Sprintf("%s/%s", chartutil.ChartsDir, c.Name)
d, err := r.Fetch(ctx, name, c.Version)
if err != nil {
Expand All @@ -180,23 +180,17 @@ func (vo *VerifyChartOption) Run(ctx context.Context) (map[*registry.Registry]ma
fallthrough
case isImageWithoutSignatureErr(err):
elem[c] = true
_ = bar.Add(1)
*row = append(*row, terminal.StatusEmoji(false))
sc.Inc("index_sign_charts")
continue
default:
return make(map[*registry.Registry]map[*helm.Chart]bool), err
}
}

elem[c] = false
*row = append(*row, terminal.StatusEmoji(true))

*row = append(*row, terminal.StatusEmoji(!elem[c]))
sc.Inc("index_sign_charts")
_ = bar.Add(1)
}

rows[c.Name] = row
}

if len(elem) > 0 {
Expand All @@ -206,7 +200,10 @@ func (vo *VerifyChartOption) Run(ctx context.Context) (map[*registry.Registry]ma

// Output table
for _, k := range keys {
vo.Report.AddRow(*rows[k])
valP := rows[k]
if valP != nil {
vo.Report.AddRow(*valP)
}
}
vo.Report.AddHeader(header)

Expand Down

0 comments on commit cca4bf6

Please sign in to comment.