Skip to content

Commit 878f273

Browse files
committed
fix: update
Signed-off-by: Junjie Gao <[email protected]>
1 parent f76559d commit 878f273

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

notation.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ type SignOptions struct {
141141
// Sign signs the OCI artifact and push the signature to the Repository.
142142
// The descriptor of the sign content is returned upon successful signing.
143143
//
144-
// Deprecated: use SignOCI instead.
144+
// Deprecated: use [SignOCI] instead.
145145
func Sign(ctx context.Context, signer Signer, repo registry.Repository, signOpts SignOptions) (ocispec.Descriptor, error) {
146146
artifactMenifestDesc, _, err := SignOCI(ctx, signer, repo, signOpts)
147147
return artifactMenifestDesc, err
@@ -151,6 +151,12 @@ func Sign(ctx context.Context, signer Signer, repo registry.Repository, signOpts
151151
//
152152
// Both artifact and signature manifest descriptors are returned upon successful
153153
// signing.
154+
//
155+
// Note: If the error type is remote.ReferrersError and
156+
// referrerError.IsReferrersIndexDelete() returns true, the signature is
157+
// successfully pushed to the repository, but the referrers index deletion
158+
// failed. In this case, the artifact and signature manifest descriptors are
159+
// returned with the error.
154160
func SignOCI(ctx context.Context, signer Signer, repo registry.Repository, signOpts SignOptions) (artifactManifestDesc, sigManifestDesc ocispec.Descriptor, err error) {
155161
// sanity check
156162
if err := validateSignArguments(signer, signOpts.SignerSignOptions); err != nil {
@@ -207,10 +213,9 @@ func SignOCI(ctx context.Context, signer Signer, repo registry.Repository, signO
207213
if err != nil {
208214
var referrerError *remote.ReferrersError
209215
if errors.As(err, &referrerError) && referrerError.IsReferrersIndexDelete() {
210-
// log warning if referrers index removal failed but signature
211-
// pushed succeeded
212-
logger.Warn("Removal of outdated referrers index from remote registry failed. Garbage collection may be required.")
213-
return artifactManifestDesc, sigManifestDesc, nil
216+
// return the descriptors for referrersIndexDelete error as
217+
// the signature is successfully pushed to the repository
218+
return artifactManifestDesc, sigManifestDesc, err
214219
}
215220
logger.Error("Failed to push the signature")
216221
return ocispec.Descriptor{}, ocispec.Descriptor{}, ErrorPushSignatureFailed{Msg: err.Error()}

notation_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ func TestSignWithDanglingReferrersIndex(t *testing.T) {
171171
opts.SignatureMediaType = jws.MediaTypeEnvelope
172172

173173
_, err := Sign(context.Background(), &dummySigner{}, repo, opts)
174-
if err != nil {
175-
t.Fatalf("expected no error as the error has been handled as a warning, got %s", err)
174+
if err == nil {
175+
t.Fatalf("no error occurred, expected error")
176176
}
177177
}
178178

0 commit comments

Comments
 (0)