digest resolves the remote digest, matching crane.Digest behavior. When a platform is set, it resolves indexes to the platform-specific image digest; otherwise it uses a cheap HEAD request and falls back to GET if HEAD fails.
(ctx context.Context, ref name.Reference)
| 171 | // platform is set, it resolves indexes to the platform-specific image digest; |
| 172 | // otherwise it uses a cheap HEAD request and falls back to GET if HEAD fails. |
| 173 | func (s *session) digest(ctx context.Context, ref name.Reference) (string, error) { |
| 174 | if s.opts.Platform != nil { |
| 175 | d, err := s.get(ctx, ref) |
| 176 | if err != nil { |
| 177 | return "", err |
| 178 | } |
| 179 | if !d.MediaType.IsIndex() { |
| 180 | return d.Digest.String(), nil |
| 181 | } |
| 182 | img, err := d.Image() |
| 183 | if err != nil { |
| 184 | return "", err |
| 185 | } |
| 186 | digest, err := img.Digest() |
| 187 | if err != nil { |
| 188 | return "", err |
| 189 | } |
| 190 | return digest.String(), nil |
| 191 | } |
| 192 | |
| 193 | var desc *v1.Descriptor |
| 194 | err := s.withFallback(func(p *remote.Puller) error { |
| 195 | var headErr error |
| 196 | desc, headErr = p.Head(ctx, ref) |
| 197 | return headErr |
| 198 | }) |
| 199 | if err == nil { |
| 200 | return desc.Digest.String(), nil |
| 201 | } |
| 202 | |
| 203 | // HEAD failed (e.g. registry doesn't support it); fall back to GET. |
| 204 | d, getErr := s.get(ctx, ref) |
| 205 | if getErr != nil { |
| 206 | return "", getErr |
| 207 | } |
| 208 | return d.Digest.String(), nil |
| 209 | } |
| 210 | |
| 211 | // image fetches the manifest and returns a lazy v1.Image whose layer reads |
| 212 | // reuse this session's authenticated fetcher. |