Skip to content

Commit

Permalink
tree: tweak reference checking
Browse files Browse the repository at this point in the history
We're already fetching the references and using them in the map, so
might as well check those when we come to print them out.

Use the SBOM suffix from ociremote rather than redefining it.

Signed-off-by: Rob Best <robertbest89@gmail.com>
  • Loading branch information
ribbybibby committed May 13, 2022
1 parent 19183b6 commit 997a01f
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions cmd/cosign/cli/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"context"
"fmt"
"os"
"strings"

v1 "github.com/google/go-containerregistry/pkg/v1"

Expand Down Expand Up @@ -47,12 +46,6 @@ func Tree() *cobra.Command {
return cmd
}

const (
SignatureTagSuffix = ".sig"
SBOMTagSuffix = ".sbom"
AttestationTagSuffix = ".att"
)

func TreeCmd(ctx context.Context, regOpts options.RegistryOptions, imageRef string) error {
scsaMap := map[name.Tag][]v1.Layer{}
ref, err := name.ParseReference(imageRef)
Expand Down Expand Up @@ -110,7 +103,7 @@ func TreeCmd(ctx context.Context, regOpts options.RegistryOptions, imageRef stri
return err
}

sbombs, err := simg.Attachment("sbom")
sbombs, err := simg.Attachment(ociremote.SBOMTagSuffix)
if err == nil {
layers, err := sbombs.Layers()
if err != nil {
Expand All @@ -128,12 +121,12 @@ func TreeCmd(ctx context.Context, regOpts options.RegistryOptions, imageRef stri
}

for t, k := range scsaMap {
switch {
case strings.HasSuffix(t.TagStr(), SignatureTagSuffix):
switch t {
case sigRef:
fmt.Fprintf(os.Stdout, "└── 🔐 Signatures for an image tag: %s\n", t.String())
case strings.HasSuffix(t.TagStr(), SBOMTagSuffix):
case sbomRef:
fmt.Fprintf(os.Stdout, "└── 📦 SBOMs for an image tag: %s\n", t.String())
case strings.HasSuffix(t.TagStr(), AttestationTagSuffix):
case attRef:
fmt.Fprintf(os.Stdout, "└── 💾 Attestations for an image tag: %s\n", t.String())
}

Expand Down

0 comments on commit 997a01f

Please sign in to comment.