Skip to content

Commit

Permalink
fix: update code
Browse files Browse the repository at this point in the history
Signed-off-by: Junjie Gao <[email protected]>
  • Loading branch information
JeyJeyGao committed Sep 1, 2023
1 parent 566c7fd commit 9dfdb3b
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions registry/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,35 +199,36 @@ func (c *repositoryClient) uploadSignatureManifest(ctx context.Context, subject,
Subject: &subject,
ManifestAnnotations: annotations,
Layers: []ocispec.Descriptor{blobDesc},
ConfigDescriptor: configDesc,
ConfigDescriptor: &configDesc,
}

return oras.PackManifest(ctx, c.GraphTarget, oras.PackManifestVersion1_1_RC4, "", opts)
}

// pushNotationManifestConfig pushes an empty notation manifest config, if it
// doesn't exist.
func pushNotationManifestConfig(ctx context.Context, pusher content.Pusher) (*ocispec.Descriptor, error) {
func pushNotationManifestConfig(ctx context.Context, pusher content.Storage) (ocispec.Descriptor, error) {
// generate a empty config descriptor for notation manifest
configContent := []byte("{}")
desc := content.NewDescriptorFromBytes(ArtifactTypeNotation, configContent)
desc := ocispec.Descriptor{
MediaType: ArtifactTypeNotation,
Digest: ocispec.DescriptorEmptyJSON.Digest,
Size: ocispec.DescriptorEmptyJSON.Size,
}

// check if the config exists
if ros, ok := pusher.(content.ReadOnlyStorage); ok {
exists, err := ros.Exists(ctx, desc)
if err != nil {
return nil, fmt.Errorf("failed to check existence: %s: %s: %w", desc.Digest.String(), desc.MediaType, err)
}
if exists {
return &desc, nil
}
exists, err := pusher.Exists(ctx, desc)
if err != nil {
return ocispec.Descriptor{}, fmt.Errorf("failed to check existence: %s: %s: %w", desc.Digest.String(), desc.MediaType, err)
}
if exists {
return desc, nil
}

// push the config
if err := pusher.Push(ctx, desc, bytes.NewReader(configContent)); err != nil && !errors.Is(err, errdef.ErrAlreadyExists) {
return nil, fmt.Errorf("failed to push: %s: %s: %w", desc.Digest.String(), desc.MediaType, err)
if err := pusher.Push(ctx, desc, bytes.NewReader(ocispec.DescriptorEmptyJSON.Data)); err != nil && !errors.Is(err, errdef.ErrAlreadyExists) {
return ocispec.Descriptor{}, fmt.Errorf("failed to push: %s: %s: %w", desc.Digest.String(), desc.MediaType, err)
}
return &desc, nil
return desc, nil
}

// signatureReferrers returns referrer nodes of desc in target filtered by
Expand Down

0 comments on commit 9dfdb3b

Please sign in to comment.