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)
| 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 |
| 79 | func (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 | |
| 105 | func (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 |
nothing calls this directly
no test coverage detected