wrapCosignErrorMessage wraps the message from the given error indicating the type of check that was performed. It may also completely change the message with a more helpful one in some cases.
(err error, checkType string, p policy.Policy)
| 334 | // type of check that was performed. It may also completely change the message |
| 335 | // with a more helpful one in some cases. |
| 336 | func wrapCosignErrorMessage(err error, checkType string, p policy.Policy) string { |
| 337 | // When NOT using the keyless workflow, the "no matching signatures" error from cosign lacks |
| 338 | // any useful information. Only in such case, change the error message to something more |
| 339 | // helpful. |
| 340 | if p == nil || !p.Keyless() { |
| 341 | switch err.(type) { |
| 342 | case *cosign.ErrNoMatchingSignatures: |
| 343 | return fmt.Sprintf(missingSignatureMessage, err) |
| 344 | case *cosign.ErrNoMatchingAttestations: |
| 345 | return fmt.Sprintf(missingAttestationMessage, err) |
| 346 | } |
| 347 | } |
| 348 | return fmt.Sprintf("Image %s check failed: %s", checkType, err) |
| 349 | } |
no test coverage detected