Skip to content

Commit 612c1e8

Browse files
committed
fix: handler referrer index deletion error
Signed-off-by: Junjie Gao <[email protected]>
1 parent deab276 commit 612c1e8

4 files changed

+24
-13
lines changed

example_remoteSign_test.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,16 @@ func Example_remoteSign() {
7070
// remote sign core process
7171
// upon successful signing, descriptor of the sign content is returned and
7272
// the generated signature is pushed into remote registry.
73-
targetDesc, err := notation.Sign(context.Background(), exampleSigner, exampleRepo, exampleSignOptions)
73+
targetManifestDesc, sigManifestDesc, err := notation.SignOCI(context.Background(), exampleSigner, exampleRepo, exampleSignOptions)
7474
if err != nil {
7575
panic(err) // Handle error
7676
}
7777

7878
fmt.Println("Successfully signed")
79-
fmt.Println("targetDesc MediaType:", targetDesc.MediaType)
80-
fmt.Println("targetDesc Digest:", targetDesc.Digest)
81-
fmt.Println("targetDesc Size:", targetDesc.Size)
79+
fmt.Println("targetManifestDesc.MediaType:", targetManifestDesc.MediaType)
80+
fmt.Println("targetManifestDesc.Digest:", targetManifestDesc.Digest)
81+
fmt.Println("targetManifestDesc.Size:", targetManifestDesc.Size)
82+
fmt.Println("sigManifestDesc.MediaType:", sigManifestDesc.MediaType)
83+
fmt.Println("sigManifestDesc.Digest:", sigManifestDesc.Digest)
84+
fmt.Println("sigManifestDesc.Size:", sigManifestDesc.Size)
8285
}

example_signWithTimestmap_test.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,16 @@ func Example_signWithTimestamp() {
9898
ArtifactReference: exampleArtifactReference,
9999
}
100100

101-
targetDesc, err := notation.Sign(context.Background(), exampleSigner, exampleRepo, exampleSignOptions)
101+
targetManifestDesc, sigManifestDesc, err := notation.SignOCI(context.Background(), exampleSigner, exampleRepo, exampleSignOptions)
102102
if err != nil {
103103
panic(err) // Handle error
104104
}
105105

106106
fmt.Println("Successfully signed")
107-
fmt.Println("targetDesc MediaType:", targetDesc.MediaType)
108-
fmt.Println("targetDesc Digest:", targetDesc.Digest)
109-
fmt.Println("targetDesc Size:", targetDesc.Size)
107+
fmt.Println("targetManifestDesc.MediaType:", targetManifestDesc.MediaType)
108+
fmt.Println("targetManifestDesc.Digest:", targetManifestDesc.Digest)
109+
fmt.Println("targetManifestDesc.Size:", targetManifestDesc.Size)
110+
fmt.Println("sigManifestDesc.MediaType:", sigManifestDesc.MediaType)
111+
fmt.Println("sigManifestDesc.Digest:", sigManifestDesc.Digest)
112+
fmt.Println("sigManifestDesc.Size:", sigManifestDesc.Size)
110113
}

notation.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ type SignOptions struct {
140140

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.
143+
//
144+
// Deprecated: Use SignOCI instead.
143145
func Sign(ctx context.Context, signer Signer, repo registry.Repository, signOpts SignOptions) (ocispec.Descriptor, error) {
144146
artifactMenifestDesc, _, err := SignOCI(ctx, signer, repo, signOpts)
145147
return artifactMenifestDesc, err
@@ -204,12 +206,15 @@ func SignOCI(ctx context.Context, signer Signer, repo registry.Repository, signO
204206
_, sigManifestDesc, err = repo.PushSignature(ctx, signOpts.SignatureMediaType, sig, artifactManifestDesc, annotations)
205207
if err != nil {
206208
var referrerError *remote.ReferrersError
207-
208-
// do not log an error for failing to delete referral index
209209
if !errors.As(err, &referrerError) || !referrerError.IsReferrersIndexDelete() {
210210
logger.Error("Failed to push the signature")
211+
return ocispec.Descriptor{}, ocispec.Descriptor{}, ErrorPushSignatureFailed{Msg: err.Error()}
211212
}
212-
return ocispec.Descriptor{}, ocispec.Descriptor{}, ErrorPushSignatureFailed{Msg: err.Error()}
213+
214+
// log warning if referrers index removal failed but signature pushed
215+
// succeeded
216+
logger.Warn("Removal of outdated referrers index from remote registry failed. Garbage collection may be required.")
217+
return artifactManifestDesc, sigManifestDesc, nil
213218
}
214219
return artifactManifestDesc, sigManifestDesc, nil
215220
}

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("no error occurred, expected error")
174+
if err != nil {
175+
t.Fatalf("expected no error as the error has been handled as a warning, got %s", err)
176176
}
177177
}
178178

0 commit comments

Comments
 (0)