| 140 | } |
| 141 | |
| 142 | func craftImage(content []byte, resource *pb.CASResource) (v1.Image, error) { |
| 143 | if len(content) == 0 { |
| 144 | return nil, errors.New("content is empty") |
| 145 | } |
| 146 | |
| 147 | if resource == nil || resource.FileName == "" || resource.Digest == "" { |
| 148 | return nil, errors.New("resource metadata is not valid") |
| 149 | } |
| 150 | |
| 151 | base := mutate.MediaType(empty.Image, types.OCIManifestSchema1) |
| 152 | base = mutate.ConfigMediaType(base, types.OCIConfigJSON) |
| 153 | base = mutate.Annotations(base, map[string]string{ |
| 154 | ocispec.AnnotationAuthors: backend.AuthorAnnotation, |
| 155 | // TODO: Move this annotation to layer |
| 156 | ocispec.AnnotationTitle: resource.FileName, |
| 157 | }).(v1.Image) |
| 158 | |
| 159 | layer := static.NewLayer(content, backend.DetectedMediaType(content)) |
| 160 | img, err := mutate.Append(base, mutate.Addendum{Layer: layer}) |
| 161 | if err != nil { |
| 162 | return nil, err |
| 163 | } |
| 164 | |
| 165 | return img, nil |
| 166 | } |
| 167 | |
| 168 | func (b *Backend) Describe(_ context.Context, digest string) (*pb.CASResource, error) { |
| 169 | if digest == "" { |