Move MediaType into manifest.Versioned

This makes content type sniffing cleaner. The document just needs to be
decoded into a manifest.Versioned structure. It's no longer a two-step
process.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
Aaron Lehmann 2016-01-06 14:15:14 -08:00
parent fce65b72b3
commit bbabb55ccb
2 changed files with 4 additions and 10 deletions

View file

@ -1096,8 +1096,8 @@ func testManifestAPISchema2(t *testing.T, env *testEnv, imageName string) manife
manifest := &schema2.Manifest{ manifest := &schema2.Manifest{
Versioned: manifest.Versioned{ Versioned: manifest.Versioned{
SchemaVersion: 2, SchemaVersion: 2,
},
MediaType: schema2.MediaTypeManifest, MediaType: schema2.MediaTypeManifest,
},
Config: distribution.Descriptor{ Config: distribution.Descriptor{
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b", Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",
Size: 3253, Size: 3253,
@ -1410,8 +1410,8 @@ func testManifestAPIManifestList(t *testing.T, env *testEnv, args manifestArgs)
manifestList := &manifestlist.ManifestList{ manifestList := &manifestlist.ManifestList{
Versioned: manifest.Versioned{ Versioned: manifest.Versioned{
SchemaVersion: 2, SchemaVersion: 2,
},
MediaType: manifestlist.MediaTypeManifestList, MediaType: manifestlist.MediaTypeManifestList,
},
Manifests: []manifestlist.ManifestDescriptor{ Manifests: []manifestlist.ManifestDescriptor{
{ {
Descriptor: distribution.Descriptor{ Descriptor: distribution.Descriptor{

View file

@ -95,19 +95,13 @@ func (ms *manifestStore) Get(ctx context.Context, dgst digest.Digest, options ..
return ms.schema1Handler.Unmarshal(ctx, dgst, content) return ms.schema1Handler.Unmarshal(ctx, dgst, content)
case 2: case 2:
// This can be an image manifest or a manifest list // This can be an image manifest or a manifest list
var mediaType struct { switch versioned.MediaType {
MediaType string `json:"mediaType"`
}
if err = json.Unmarshal(content, &mediaType); err != nil {
return nil, err
}
switch mediaType.MediaType {
case schema2.MediaTypeManifest: case schema2.MediaTypeManifest:
return ms.schema2Handler.Unmarshal(ctx, dgst, content) return ms.schema2Handler.Unmarshal(ctx, dgst, content)
case manifestlist.MediaTypeManifestList: case manifestlist.MediaTypeManifestList:
return ms.manifestListHandler.Unmarshal(ctx, dgst, content) return ms.manifestListHandler.Unmarshal(ctx, dgst, content)
default: default:
return nil, distribution.ErrManifestVerification{fmt.Errorf("unrecognized manifest content type %s", mediaType.MediaType)} return nil, distribution.ErrManifestVerification{fmt.Errorf("unrecognized manifest content type %s", versioned.MediaType)}
} }
} }