Skip to content

Commit

Permalink
Update: added ErrorPushSignatureFailed (#271)
Browse files Browse the repository at this point in the history
This PR adds a `ErrorPushSignatureFailed` error type so that users of notation.Sign() would be able to check error type on Signing failures. On notation CLI side, if the error is of type `ErrorPushSignatureFailed`, a suggestion of using OCI image manifest will be printed out.

Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>
  • Loading branch information
Two-Hearts committed Feb 7, 2023
1 parent 920ded2 commit 5e5cba1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package notation

//
type ErrorPushSignatureFailed struct {
Msg string
}

func (e ErrorPushSignatureFailed) Error() string {
if e.Msg != "" {
return "failed to push signature to registry with error: " + e.Msg
}
return "failed to push signature to registry"
}

// ErrorVerificationInconclusive is used when signature verification fails due to a runtime error (e.g. a network error)
type ErrorVerificationInconclusive struct {
Msg string
Expand Down
4 changes: 2 additions & 2 deletions notation.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func Sign(ctx context.Context, signer Signer, repo registry.Repository, opts Sig
_, _, err = repo.PushSignature(ctx, opts.SignatureMediaType, sig, targetDesc, annotations)
if err != nil {
logger.Error("Failed to push the signature")
return ocispec.Descriptor{}, err
return ocispec.Descriptor{}, ErrorPushSignatureFailed{Msg: err.Error()}
}

return targetDesc, nil
Expand Down Expand Up @@ -339,4 +339,4 @@ func generateAnnotations(signerInfo *signature.SignerInfo, annotations map[strin

annotations[annotationX509ChainThumbprint] = string(val)
return annotations, nil
}
}

0 comments on commit 5e5cba1

Please sign in to comment.