|
|
|
@ -390,6 +390,7 @@ type (
|
|
|
|
|
Chart *DescriptorPullSummaryWithMeta `json:"chart"`
|
|
|
|
|
Prov *DescriptorPullSummary `json:"prov"`
|
|
|
|
|
Ref string `json:"ref"`
|
|
|
|
|
Values *DescriptorPullSummary `json:"values"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DescriptorPullSummary struct {
|
|
|
|
@ -427,24 +428,23 @@ func (c *Client) Pull(ref string, options ...PullOption) (*PullResult, error) {
|
|
|
|
|
return nil, errors.New(
|
|
|
|
|
"must specify at least one layer to pull (chart/prov)")
|
|
|
|
|
}
|
|
|
|
|
memoryStore := memory.New()
|
|
|
|
|
allowedMediaTypes := []string{
|
|
|
|
|
ocispec.MediaTypeImageManifest,
|
|
|
|
|
ConfigMediaType,
|
|
|
|
|
}
|
|
|
|
|
minNumDescriptors := 1 // 1 for the config
|
|
|
|
|
if operation.withChart {
|
|
|
|
|
minNumDescriptors++
|
|
|
|
|
allowedMediaTypes = append(allowedMediaTypes, ChartLayerMediaType, LegacyChartLayerMediaType)
|
|
|
|
|
}
|
|
|
|
|
if operation.withProv {
|
|
|
|
|
if !operation.ignoreMissingProv {
|
|
|
|
|
minNumDescriptors++
|
|
|
|
|
}
|
|
|
|
|
allowedMediaTypes = append(allowedMediaTypes, ProvLayerMediaType)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var descriptors, layers []ocispec.Descriptor
|
|
|
|
|
memoryStore := memory.New()
|
|
|
|
|
//allowedMediaTypes := []string{
|
|
|
|
|
// ocispec.MediaTypeImageManifest,
|
|
|
|
|
// ConfigMediaType,
|
|
|
|
|
//}
|
|
|
|
|
//minNumDescriptors := 1 // 1 for the config
|
|
|
|
|
//if operation.withChart {
|
|
|
|
|
// minNumDescriptors++
|
|
|
|
|
// allowedMediaTypes = append(allowedMediaTypes, ChartLayerMediaType, LegacyChartLayerMediaType)
|
|
|
|
|
//}
|
|
|
|
|
//if operation.withProv {
|
|
|
|
|
// if !operation.ignoreMissingProv {
|
|
|
|
|
// minNumDescriptors++
|
|
|
|
|
// }
|
|
|
|
|
// allowedMediaTypes = append(allowedMediaTypes, ProvLayerMediaType)
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
repository, err := remote.NewRepository(parsedRef.String())
|
|
|
|
|
if err != nil {
|
|
|
|
@ -455,16 +455,17 @@ func (c *Client) Pull(ref string, options ...PullOption) (*PullResult, error) {
|
|
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
sort.Strings(allowedMediaTypes)
|
|
|
|
|
//sort.Strings(allowedMediaTypes)
|
|
|
|
|
|
|
|
|
|
var mu sync.Mutex
|
|
|
|
|
var layers []ocispec.Descriptor
|
|
|
|
|
manifest, err := oras.Copy(ctx, repository, parsedRef.String(), memoryStore, "", oras.CopyOptions{
|
|
|
|
|
CopyGraphOptions: oras.CopyGraphOptions{
|
|
|
|
|
PreCopy: func(_ context.Context, desc ocispec.Descriptor) error {
|
|
|
|
|
mediaType := desc.MediaType
|
|
|
|
|
if i := sort.SearchStrings(allowedMediaTypes, mediaType); i >= len(allowedMediaTypes) || allowedMediaTypes[i] != mediaType {
|
|
|
|
|
return errors.Errorf("media type %q is not allowed, found in descriptor with digest: %q", mediaType, desc.Digest)
|
|
|
|
|
}
|
|
|
|
|
//mediaType := desc.MediaType
|
|
|
|
|
//if i := sort.SearchStrings(allowedMediaTypes, mediaType); i >= len(allowedMediaTypes) || allowedMediaTypes[i] != mediaType {
|
|
|
|
|
// return errors.Errorf("media type %q is not allowed, found in descriptor with digest: %q", mediaType, desc.Digest)
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
mu.Lock()
|
|
|
|
|
layers = append(layers, desc)
|
|
|
|
@ -477,17 +478,19 @@ func (c *Client) Pull(ref string, options ...PullOption) (*PullResult, error) {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var descriptors []ocispec.Descriptor
|
|
|
|
|
descriptors = append(descriptors, manifest)
|
|
|
|
|
descriptors = append(descriptors, layers...)
|
|
|
|
|
|
|
|
|
|
numDescriptors := len(descriptors)
|
|
|
|
|
if numDescriptors < minNumDescriptors {
|
|
|
|
|
return nil, fmt.Errorf("manifest does not contain minimum number of descriptors (%d), descriptors found: %d",
|
|
|
|
|
minNumDescriptors, numDescriptors)
|
|
|
|
|
if manifest.MediaType != "application/vnd.oci.image.manifest.v1+json" {
|
|
|
|
|
return nil, fmt.Errorf("unexpected reference mediatype: %s", manifest.MediaType)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var configDescriptor *ocispec.Descriptor
|
|
|
|
|
var chartDescriptor *ocispec.Descriptor
|
|
|
|
|
var provDescriptor *ocispec.Descriptor
|
|
|
|
|
var valuesDescriptor *ocispec.Descriptor
|
|
|
|
|
|
|
|
|
|
for _, descriptor := range descriptors {
|
|
|
|
|
d := descriptor
|
|
|
|
|
switch d.MediaType {
|
|
|
|
@ -497,11 +500,30 @@ func (c *Client) Pull(ref string, options ...PullOption) (*PullResult, error) {
|
|
|
|
|
chartDescriptor = &d
|
|
|
|
|
case ProvLayerMediaType:
|
|
|
|
|
provDescriptor = &d
|
|
|
|
|
case ValuesMediaType:
|
|
|
|
|
valuesDescriptor = &d
|
|
|
|
|
case LegacyChartLayerMediaType:
|
|
|
|
|
chartDescriptor = &d
|
|
|
|
|
fmt.Fprintf(c.out, "Warning: chart media type %s is deprecated\n", LegacyChartLayerMediaType)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if valuesDescriptor != nil {
|
|
|
|
|
data, err := content.FetchAll(ctx, memoryStore, *valuesDescriptor)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("unable to retrieve blob with digest %s: %w", valuesDescriptor.Digest, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &PullResult{
|
|
|
|
|
Ref: parsedRef.String(),
|
|
|
|
|
Values: &DescriptorPullSummary{
|
|
|
|
|
Digest: valuesDescriptor.Digest.String(),
|
|
|
|
|
Size: valuesDescriptor.Size,
|
|
|
|
|
Data: data,
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if configDescriptor == nil {
|
|
|
|
|
return nil, fmt.Errorf("could not load config with mediatype %s", ConfigMediaType)
|
|
|
|
|
}
|
|
|
|
@ -530,6 +552,7 @@ func (c *Client) Pull(ref string, options ...PullOption) (*PullResult, error) {
|
|
|
|
|
Chart: &DescriptorPullSummaryWithMeta{},
|
|
|
|
|
Prov: &DescriptorPullSummary{},
|
|
|
|
|
Ref: parsedRef.String(),
|
|
|
|
|
Values: nil,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.Manifest.Data, err = content.FetchAll(ctx, memoryStore, manifest)
|
|
|
|
|