(_ context.Context, digest string)
| 166 | } |
| 167 | |
| 168 | func (b *Backend) Describe(_ context.Context, digest string) (*pb.CASResource, error) { |
| 169 | if digest == "" { |
| 170 | return nil, errors.New("digest is empty") |
| 171 | } |
| 172 | |
| 173 | ref, err := name.ParseReference(b.resourcePath(digest)) |
| 174 | if err != nil { |
| 175 | return nil, fmt.Errorf("parsing reference: %w", err) |
| 176 | } |
| 177 | |
| 178 | img, err := remote.Image(ref, remote.WithAuthFromKeychain(b.keychain)) |
| 179 | if err != nil { |
| 180 | var e *transport.Error |
| 181 | if errors.As(err, &e) && e.StatusCode == http.StatusNotFound { |
| 182 | return nil, backend.NewErrNotFound("image") |
| 183 | } |
| 184 | |
| 185 | return nil, fmt.Errorf("getting image: %w", err) |
| 186 | } |
| 187 | |
| 188 | if err := validateImage(img, digest); err != nil { |
| 189 | return nil, fmt.Errorf("validating image: %w", err) |
| 190 | } |
| 191 | |
| 192 | manifest, err := img.Manifest() |
| 193 | if err != nil { |
| 194 | return nil, fmt.Errorf("extracting manifest: %w", err) |
| 195 | } |
| 196 | |
| 197 | // Validate image already checked that the manifest has exactly one layer |
| 198 | size := manifest.Layers[0].Size |
| 199 | |
| 200 | filename, ok := manifest.Annotations[ocispec.AnnotationTitle] |
| 201 | if !ok { |
| 202 | return nil, errors.New("couldn't find file metadata") |
| 203 | } |
| 204 | |
| 205 | return &pb.CASResource{Digest: digest, FileName: filename, Size: size}, nil |
| 206 | } |
| 207 | |
| 208 | func (b *Backend) Download(_ context.Context, w io.Writer, digest string) error { |
| 209 | if digest == "" { |
nothing calls this directly
no test coverage detected