Skip to content

Commit

Permalink
feat: set cosign attest predicate type based on Syft output type
Browse files Browse the repository at this point in the history
Signed-off-by: Nils Hanke <nils.hanke@outlook.de>
  • Loading branch information
Nirusu committed Feb 21, 2023
1 parent 2ef2eed commit 1d2c789
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/syft/cli/attest/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"strings"

"github.com/wagoodman/go-partybus"
"github.com/wagoodman/go-progress"
Expand Down Expand Up @@ -130,7 +131,21 @@ func execWorker(app *config.Application, si source.Input, writer sbom.Writer) <-
return
}

args := []string{"attest", si.UserInput, "--predicate", f.Name()}
// Select Cosign predicate type based on defined output type
// As orientation, check: https://github.com/sigstore/cosign/blob/main/pkg/cosign/attestation/attestation.go
var predicateType string
switch strings.ToLower(o) {
case "cyclonedx-json":
predicateType = "cyclonedx"
case "spdx-tag-value":
predicateType = "spdx"
case "spdx-json":
predicateType = "spdxjson"
default:
predicateType = "custom"
}

args := []string{"attest", si.UserInput, "--predicate", f.Name(), "--type", predicateType}
if app.Attest.Key != "" {
args = append(args, "--key", app.Attest.Key)
}
Expand Down

0 comments on commit 1d2c789

Please sign in to comment.