in registry/handlers/manifests.go [544:614]
func dbManifestToManifest(dbm *models.Manifest) (distribution.Manifest, error) {
if dbm.SchemaVersion == 1 {
return nil, distribution.ErrSchemaV1Unsupported
}
if dbm.SchemaVersion != 2 {
return nil, fmt.Errorf("unrecognized manifest schema version %d", dbm.SchemaVersion)
}
mediaType := dbm.MediaType
if dbm.NonConformant {
// parse payload and get real media type
var versioned manifest.Versioned
if err := json.Unmarshal(dbm.Payload, &versioned); err != nil {
return nil, fmt.Errorf("failed to unmarshal manifest payload: %w", err)
}
mediaType = versioned.MediaType
}
// TODO: Each case here is taken directly from the respective
// registry/storage/*manifesthandler Unmarshal method. We cannot invoke them
// directly as they are unexported, but they are relatively simple. We should
// determine a single place for this logic during refactoring
// https://gitlab.com/gitlab-org/container-registry/-/issues/135
// This can be an image manifest or a manifest list
switch mediaType {
case schema2.MediaTypeManifest:
m := &schema2.DeserializedManifest{}
if err := m.UnmarshalJSON(dbm.Payload); err != nil {
return nil, err
}
return m, nil
case v1.MediaTypeImageManifest:
m := &ocischema.DeserializedManifest{}
if err := m.UnmarshalJSON(dbm.Payload); err != nil {
return nil, err
}
return m, nil
case manifestlist.MediaTypeManifestList, v1.MediaTypeImageIndex:
m := &manifestlist.DeserializedManifestList{}
if err := m.UnmarshalJSON(dbm.Payload); err != nil {
return nil, err
}
return m, nil
case "":
// OCI image or image index - no media type in the content
// First see if it looks like an image index
resIndex := &manifestlist.DeserializedManifestList{}
if err := resIndex.UnmarshalJSON(dbm.Payload); err != nil {
return nil, err
}
if resIndex.Manifests != nil {
return resIndex, nil
}
// Otherwise, assume it must be an image manifest
m := &ocischema.DeserializedManifest{}
if err := m.UnmarshalJSON(dbm.Payload); err != nil {
return nil, err
}
return m, nil
default:
return nil, distribution.ErrManifestVerification{fmt.Errorf("unrecognized manifest content type %s", dbm.MediaType)}
}
}