annotateDistributionSourceHandler add distribution source label into annotation of config or blob descriptor.
(f images.HandlerFunc, provider content.InfoProvider)
| 356 | // annotateDistributionSourceHandler add distribution source label into |
| 357 | // annotation of config or blob descriptor. |
| 358 | func annotateDistributionSourceHandler(f images.HandlerFunc, provider content.InfoProvider) images.HandlerFunc { |
| 359 | return func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { |
| 360 | children, err := f(ctx, desc) |
| 361 | if err != nil { |
| 362 | return nil, err |
| 363 | } |
| 364 | |
| 365 | // Distribution source is only used for config or blob but may be inherited from |
| 366 | // a manifest or manifest list |
| 367 | if !images.IsManifestType(desc.MediaType) && !images.IsIndexType(desc.MediaType) { |
| 368 | return children, nil |
| 369 | } |
| 370 | |
| 371 | parentSourceAnnotations := desc.Annotations |
| 372 | var parentLabels map[string]string |
| 373 | if pi, err := provider.Info(ctx, desc.Digest); err != nil { |
| 374 | if !errdefs.IsNotFound(err) { |
| 375 | return nil, err |
| 376 | } |
| 377 | } else { |
| 378 | parentLabels = pi.Labels |
| 379 | } |
| 380 | |
| 381 | for i := range children { |
| 382 | child := children[i] |
| 383 | |
| 384 | info, err := provider.Info(ctx, child.Digest) |
| 385 | if err != nil { |
| 386 | if !errdefs.IsNotFound(err) { |
| 387 | return nil, err |
| 388 | } |
| 389 | } |
| 390 | copyDistributionSourceLabels(info.Labels, &child) |
| 391 | |
| 392 | // Annotate with parent labels for cross repo mount or fetch. |
| 393 | // Parent sources may apply to all children since most registries |
| 394 | // enforce that children exist before the manifests. |
| 395 | copyDistributionSourceLabels(parentSourceAnnotations, &child) |
| 396 | copyDistributionSourceLabels(parentLabels, &child) |
| 397 | |
| 398 | children[i] = child |
| 399 | } |
| 400 | return children, nil |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | func copyDistributionSourceLabels(from map[string]string, to *ocispec.Descriptor) { |
| 405 | for k, v := range from { |
no test coverage detected
searching dependent graphs…