MCPcopy
hub / github.com/google/go-containerregistry / Descriptor

Function Descriptor

pkg/v1/partial/with.go:310–351  ·  view source on GitHub ↗

Descriptor returns a v1.Descriptor given a Describable. It also encodes some logic for unwrapping things that have been wrapped by CompressedToLayer, UncompressedToLayer, CompressedToImage, or UncompressedToImage.

(d Describable)

Source from the content-addressed store, hash-verified

308// CompressedToLayer, UncompressedToLayer, CompressedToImage, or
309// UncompressedToImage.
310func Descriptor(d Describable) (*v1.Descriptor, error) {
311 // If Describable implements Descriptor itself, return that.
312 if wd, ok := unwrap(d).(withDescriptor); ok {
313 return wd.Descriptor()
314 }
315
316 // If all else fails, compute the descriptor from the individual methods.
317 var (
318 desc v1.Descriptor
319 err error
320 )
321
322 if desc.Size, err = d.Size(); err != nil {
323 return nil, err
324 }
325 if desc.Digest, err = d.Digest(); err != nil {
326 return nil, err
327 }
328 if desc.MediaType, err = d.MediaType(); err != nil {
329 return nil, err
330 }
331 if wat, ok := d.(withArtifactType); ok {
332 if desc.ArtifactType, err = wat.ArtifactType(); err != nil {
333 return nil, err
334 }
335 } else {
336 if wrm, ok := d.(WithRawManifest); ok && desc.MediaType.IsImage() {
337 mf, _ := Manifest(wrm)
338 // Failing to parse as a manifest should just be ignored.
339 // The manifest might not be valid, and that's okay.
340 if mf != nil {
341 if mf.ArtifactType != "" {
342 desc.ArtifactType = mf.ArtifactType
343 } else {
344 desc.ArtifactType = string(mf.Config.MediaType)
345 }
346 }
347 }
348 }
349
350 return &desc, nil
351}
352
353type withArtifactType interface {
354 ArtifactType() (string, error)

Callers 15

AppendImageMethod · 0.92
AppendIndexMethod · 0.92
replaceDescriptorMethod · 0.92
DescriptorMethod · 0.92
DescriptorMethod · 0.92
TestPullingManifestListFunction · 0.92
TestNestedIndexFunction · 0.92
TestUncompressedLayerFunction · 0.92
DescriptorMethod · 0.92
TestUncompressedFunction · 0.92

Calls 8

unwrapFunction · 0.85
IsImageMethod · 0.80
ManifestFunction · 0.70
DescriptorMethod · 0.65
SizeMethod · 0.65
DigestMethod · 0.65
MediaTypeMethod · 0.65
ArtifactTypeMethod · 0.65

Tested by 12

TestPullingManifestListFunction · 0.74
TestNestedIndexFunction · 0.74
TestUncompressedLayerFunction · 0.74
DescriptorMethod · 0.74
TestUncompressedFunction · 0.74
DescriptorMethod · 0.74
DescriptorMethod · 0.74
TestCompressedFunction · 0.74
TestAppend_ArtifactTypeFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…