(provider content.Provider, matcher platforms.MatchComparer)
| 158 | } |
| 159 | |
| 160 | func imageConfigMetadataChildrenHandler(provider content.Provider, matcher platforms.MatchComparer) images.HandlerFunc { |
| 161 | return func(ctx context.Context, desc ocispecs.Descriptor) ([]ocispecs.Descriptor, error) { |
| 162 | switch { |
| 163 | case images.IsIndexType(desc.MediaType): |
| 164 | p, err := content.ReadBlob(ctx, provider, desc) |
| 165 | if err != nil { |
| 166 | return nil, err |
| 167 | } |
| 168 | var idx ocispecs.Index |
| 169 | if err := json.Unmarshal(p, &idx); err != nil { |
| 170 | return nil, err |
| 171 | } |
| 172 | candidates := matchingPlatformManifests(idx.Manifests, matcher) |
| 173 | if len(candidates) == 0 { |
| 174 | return nil, fmt.Errorf("no manifest matches requested platform for %s", desc.Digest) |
| 175 | } |
| 176 | return candidates[:1], nil |
| 177 | |
| 178 | case images.IsManifestType(desc.MediaType): |
| 179 | p, err := content.ReadBlob(ctx, provider, desc) |
| 180 | if err != nil { |
| 181 | return nil, err |
| 182 | } |
| 183 | var manifest ocispecs.Manifest |
| 184 | if err := json.Unmarshal(p, &manifest); err != nil { |
| 185 | return nil, err |
| 186 | } |
| 187 | return []ocispecs.Descriptor{manifest.Config}, nil |
| 188 | |
| 189 | case images.IsLayerType(desc.MediaType): |
| 190 | return nil, images.ErrSkipDesc |
| 191 | |
| 192 | default: |
| 193 | return nil, nil |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | func matchingPlatformManifests(manifests []ocispecs.Descriptor, matcher platforms.MatchComparer) []ocispecs.Descriptor { |
| 199 | candidates := make([]ocispecs.Descriptor, 0, len(manifests)) |
no test coverage detected