images: simplify mediatype logic
Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
This commit is contained in:
parent
377c5ca9cd
commit
62f621a344
@ -321,7 +321,6 @@ func Check(ctx context.Context, provider content.Provider, image ocispec.Descrip
|
|||||||
|
|
||||||
// Children returns the immediate children of content described by the descriptor.
|
// Children returns the immediate children of content described by the descriptor.
|
||||||
func Children(ctx context.Context, provider content.Provider, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
func Children(ctx context.Context, provider content.Provider, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
||||||
var descs []ocispec.Descriptor
|
|
||||||
if IsManifestType(desc.MediaType) {
|
if IsManifestType(desc.MediaType) {
|
||||||
p, err := content.ReadBlob(ctx, provider, desc)
|
p, err := content.ReadBlob(ctx, provider, desc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -339,8 +338,7 @@ func Children(ctx context.Context, provider content.Provider, desc ocispec.Descr
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
descs = append(descs, manifest.Config)
|
return append([]ocispec.Descriptor{manifest.Config}, manifest.Layers...), nil
|
||||||
descs = append(descs, manifest.Layers...)
|
|
||||||
} else if IsIndexType(desc.MediaType) {
|
} else if IsIndexType(desc.MediaType) {
|
||||||
p, err := content.ReadBlob(ctx, provider, desc)
|
p, err := content.ReadBlob(ctx, provider, desc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -356,16 +354,12 @@ func Children(ctx context.Context, provider content.Provider, desc ocispec.Descr
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
descs = append(descs, index.Manifests...)
|
return append([]ocispec.Descriptor{}, index.Manifests...), nil
|
||||||
} else {
|
} else if !IsLayerType(desc.MediaType) && !IsKnownConfig(desc.MediaType) {
|
||||||
if IsLayerType(desc.MediaType) || IsKnownConfig(desc.MediaType) {
|
// Layers and configs are childless data types and should not be logged.
|
||||||
// childless data types.
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
log.G(ctx).Debugf("encountered unknown type %v; children may not be fetched", desc.MediaType)
|
log.G(ctx).Debugf("encountered unknown type %v; children may not be fetched", desc.MediaType)
|
||||||
}
|
}
|
||||||
|
return nil, nil
|
||||||
return descs, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// unknownDocument represents a manifest, manifest list, or index that has not
|
// unknownDocument represents a manifest, manifest list, or index that has not
|
||||||
@ -378,9 +372,10 @@ type unknownDocument struct {
|
|||||||
FSLayers json.RawMessage `json:"fsLayers,omitempty"` // schema 1
|
FSLayers json.RawMessage `json:"fsLayers,omitempty"` // schema 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateMediaType returns an error if the byte slice is invalid JSON or if
|
// validateMediaType returns an error if the byte slice is invalid JSON,
|
||||||
// the media type identifies the blob as one format but it contains elements of
|
// if the format of the blob is not supported, or if the media type
|
||||||
// another format.
|
// identifies the blob as one format, but it identifies itself as, or
|
||||||
|
// contains elements of another format.
|
||||||
func validateMediaType(b []byte, mt string) error {
|
func validateMediaType(b []byte, mt string) error {
|
||||||
var doc unknownDocument
|
var doc unknownDocument
|
||||||
if err := json.Unmarshal(b, &doc); err != nil {
|
if err := json.Unmarshal(b, &doc); err != nil {
|
||||||
@ -389,15 +384,10 @@ func validateMediaType(b []byte, mt string) error {
|
|||||||
if len(doc.FSLayers) != 0 {
|
if len(doc.FSLayers) != 0 {
|
||||||
return fmt.Errorf("media-type: schema 1 not supported")
|
return fmt.Errorf("media-type: schema 1 not supported")
|
||||||
}
|
}
|
||||||
if IsManifestType(mt) {
|
if IsManifestType(mt) && (len(doc.Manifests) != 0 || IsIndexType(doc.MediaType)) {
|
||||||
if len(doc.Manifests) != 0 || IsIndexType(doc.MediaType) {
|
return fmt.Errorf("media-type: expected manifest but found index (%s)", mt)
|
||||||
return fmt.Errorf("media-type: expected manifest but found index (%s)", mt)
|
} else if IsIndexType(mt) && (len(doc.Config) != 0 || len(doc.Layers) != 0 || IsManifestType(doc.MediaType)) {
|
||||||
}
|
return fmt.Errorf("media-type: expected index but found manifest (%s)", mt)
|
||||||
} else if IsIndexType(mt) {
|
|
||||||
if len(doc.Config) != 0 || len(doc.Layers) != 0 || IsManifestType(doc.MediaType) {
|
|
||||||
return fmt.Errorf("media-type: expected index but found manifest (%s)", mt)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user