Skip to content

Commit

Permalink
Add sbom to triangulate
Browse files Browse the repository at this point in the history
Signed-off-by: Sambhav Kothari <sambhavs.email@gmail.com>
  • Loading branch information
sambhav committed Sep 6, 2021
1 parent 5abd51e commit aeaaf26
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cmd/cosign/cli/triangulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,23 @@ import (
func Triangulate() *ffcli.Command {
var (
flagset = flag.NewFlagSet("cosign triangulate", flag.ExitOnError)
t = flagset.String("type", "signature", "related attachment to triangulate (sbom|signature), default signature")
)
return &ffcli.Command{
Name: "triangulate",
ShortUsage: "cosign triangulate <image uri>",
ShortHelp: "Outputs the located cosign image reference. This is the location cosign stores signatures.",
ShortHelp: "Outputs the located cosign image reference. This is the location cosign stores signatures or sboms.",
FlagSet: flagset,
Exec: func(ctx context.Context, args []string) error {
if len(args) != 1 {
return flag.ErrHelp
}
return MungeCmd(ctx, args[0])
return MungeCmd(ctx, args[0], *t)
},
}
}

func MungeCmd(ctx context.Context, imageRef string) error {
func MungeCmd(ctx context.Context, imageRef string, attachmentType string) error {
ref, err := name.ParseReference(imageRef)
if err != nil {
return err
Expand All @@ -59,7 +60,15 @@ func MungeCmd(ctx context.Context, imageRef string) error {
if err != nil {
return err
}
dstRef := cosign.AttachedImageTag(sigRepo, h, cosign.SignatureTagSuffix)
var dstRef name.Tag
switch attachmentType {
case "signature":
dstRef = cosign.AttachedImageTag(sigRepo, h, cosign.SignatureTagSuffix)
case "sbom":
dstRef = cosign.AttachedImageTag(sigRepo, h, cosign.SBOMTagSuffix)
default:
return fmt.Errorf("unknown attachment type %s", attachmentType)
}

fmt.Println(dstRef.Name())
return nil
Expand Down

0 comments on commit aeaaf26

Please sign in to comment.