bug: remove chance for panic; provide default attestation path (#1214)

This commit is contained in:
Christopher Angelo Phillips 2022-09-19 11:50:33 -04:00 committed by GitHub
parent ad263e6562
commit 0f99215b2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -70,7 +70,14 @@ func Run(ctx context.Context, app *config.Application, ko sigopts.KeyOpts, args
return err return err
} }
format := syft.FormatByName(app.Outputs[0]) output := parseAttestationOutput(app.Outputs)
format := syft.FormatByName(output)
// user typo or unknown outputs provided
if format == nil {
format = syft.FormatByID(syftjson.ID) // default attestation format
}
predicateType := formatPredicateType(format) predicateType := formatPredicateType(format)
if predicateType == "" { if predicateType == "" {
return fmt.Errorf( return fmt.Errorf(
@ -109,6 +116,14 @@ func Run(ctx context.Context, app *config.Application, ko sigopts.KeyOpts, args
) )
} }
func parseAttestationOutput(outputs []string) (format string) {
if len(outputs) == 0 {
outputs = append(outputs, string(syftjson.ID))
}
return outputs[0]
}
func parseImageSource(userInput string, app *config.Application) (s *source.Input, err error) { func parseImageSource(userInput string, app *config.Application) (s *source.Input, err error) {
si, err := source.ParseInput(userInput, app.Platform, false) si, err := source.ParseInput(userInput, app.Platform, false)
if err != nil { if err != nil {

View File

@ -40,6 +40,14 @@ func TestAttestCmd(t *testing.T) {
}, },
pw: "", pw: "",
}, },
{
name: "can encode syft.json as the predicate given a user format typo",
args: []string{"attest", "-o", "spdx-jsonx", "--key", "cosign.key", img},
assertions: []traitAssertion{
assertSuccessfulReturnCode,
},
pw: "",
},
} }
for _, test := range tests { for _, test := range tests {