processChartPull handles chart-specific processing of a generic pull result
(genericResult *GenericPullResult, operation *pullOperation)
| 437 | |
| 438 | // processChartPull handles chart-specific processing of a generic pull result |
| 439 | func (c *Client) processChartPull(genericResult *GenericPullResult, operation *pullOperation) (*PullResult, error) { |
| 440 | var err error |
| 441 | |
| 442 | // Chart-specific validation |
| 443 | minNumDescriptors := 1 // 1 for the config |
| 444 | if operation.withChart { |
| 445 | minNumDescriptors++ |
| 446 | } |
| 447 | if operation.withProv && !operation.ignoreMissingProv { |
| 448 | minNumDescriptors++ |
| 449 | } |
| 450 | |
| 451 | numDescriptors := len(genericResult.Descriptors) |
| 452 | if numDescriptors < minNumDescriptors { |
| 453 | return nil, fmt.Errorf("manifest does not contain minimum number of descriptors (%d), descriptors found: %d", |
| 454 | minNumDescriptors, numDescriptors) |
| 455 | } |
| 456 | |
| 457 | // Find chart-specific descriptors |
| 458 | var configDescriptor *ocispec.Descriptor |
| 459 | var chartDescriptor *ocispec.Descriptor |
| 460 | var provDescriptor *ocispec.Descriptor |
| 461 | |
| 462 | for _, descriptor := range genericResult.Descriptors { |
| 463 | d := descriptor |
| 464 | switch d.MediaType { |
| 465 | case ConfigMediaType: |
| 466 | configDescriptor = &d |
| 467 | case ChartLayerMediaType: |
| 468 | chartDescriptor = &d |
| 469 | case ProvLayerMediaType: |
| 470 | provDescriptor = &d |
| 471 | case LegacyChartLayerMediaType: |
| 472 | chartDescriptor = &d |
| 473 | _, _ = fmt.Fprintf(c.out, "Warning: chart media type %s is deprecated\n", LegacyChartLayerMediaType) |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | // Chart-specific validation |
| 478 | if configDescriptor == nil { |
| 479 | return nil, fmt.Errorf("could not load config with mediatype %s", ConfigMediaType) |
| 480 | } |
| 481 | if operation.withChart && chartDescriptor == nil { |
| 482 | return nil, fmt.Errorf("manifest does not contain a layer with mediatype %s", |
| 483 | ChartLayerMediaType) |
| 484 | } |
| 485 | |
| 486 | var provMissing bool |
| 487 | if operation.withProv && provDescriptor == nil { |
| 488 | if operation.ignoreMissingProv { |
| 489 | provMissing = true |
| 490 | } else { |
| 491 | return nil, fmt.Errorf("manifest does not contain a layer with mediatype %s", |
| 492 | ProvLayerMediaType) |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | // Build chart-specific result |
no test coverage detected