MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / Exists

Method Exists

pkg/blobmanager/oci/backend.go:79–103  ·  view source on GitHub ↗

Exists check that the artifact is already present in the repository and it points to the same image digest, meaning it has not been re-pushed/replaced This method is very naive so signatures will be used in future releases

(_ context.Context, digest string)

Source from the content-addressed store, hash-verified

77// same image digest, meaning it has not been re-pushed/replaced
78// This method is very naive so signatures will be used in future releases
79func (b *Backend) Exists(_ context.Context, digest string) (bool, error) {
80 if digest == "" {
81 return false, errors.New("digest is empty")
82 }
83
84 ref, err := name.ParseReference(b.resourcePath(digest))
85 if err != nil {
86 return false, err
87 }
88
89 // It's not trivial to catch if the error is a 404 (yeah I know...) so we will assume that
90 // any error means no and will be caught in the next stage when we try to upload the image
91 image, err := remote.Image(ref, remote.WithAuthFromKeychain(b.keychain))
92 if err != nil {
93 // Image is not there
94 return false, nil
95 }
96
97 // If the image is not a valid chainloop image we will return false
98 if err := validateImage(image, digest); err != nil {
99 return false, nil
100 }
101
102 return true, nil
103}
104
105func (b *Backend) Upload(_ context.Context, r io.Reader, resource *pb.CASResource) error {
106 // We need to read the whole content before uploading it to the registry

Callers

nothing calls this directly

Calls 2

resourcePathMethod · 0.95
validateImageFunction · 0.85

Tested by

no test coverage detected