This repository has been archived by the owner on Jul 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
manifesthandler.go
66 lines (54 loc) · 2.5 KB
/
manifesthandler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package server
import (
"fmt"
"github.com/docker/distribution"
"github.com/docker/distribution/context"
"github.com/docker/distribution/manifest/schema1"
"github.com/docker/distribution/manifest/schema2"
imageapi "github.com/openshift/origin/pkg/image/api"
)
// A ManifestHandler defines a common set of operations on all versions of manifest schema.
type ManifestHandler interface {
// FillImageMetadata fills a given image with metadata parsed from manifest. It also corrects layer sizes
// with blob sizes. Newer Docker client versions don't set layer sizes in the manifest schema 1 at all.
// Origin master needs correct layer sizes for proper image quota support. That's why we need to fill the
// metadata in the registry.
FillImageMetadata(ctx context.Context, image *imageapi.Image) error
// Manifest returns a deserialized manifest object.
Manifest() distribution.Manifest
// Payload returns manifest's media type, complete payload with signatures and canonical payload without
// signatures or an error if the information could not be fetched.
Payload() (mediaType string, payload []byte, canonical []byte, err error)
// Verify returns an error if the contained manifest is not valid or has missing dependencies.
Verify(ctx context.Context, skipDependencyVerification bool) error
}
// NewManifestHandler creates a manifest handler for the given manifest.
func NewManifestHandler(repo *repository, manifest distribution.Manifest) (ManifestHandler, error) {
switch t := manifest.(type) {
case *schema1.SignedManifest:
return &manifestSchema1Handler{repo: repo, manifest: t}, nil
case *schema2.DeserializedManifest:
return &manifestSchema2Handler{repo: repo, manifest: t}, nil
default:
return nil, fmt.Errorf("unsupported manifest type %T", manifest)
}
}
// NewManifestHandlerFromImage creates a new manifest handler for a manifest stored in the given image.
func NewManifestHandlerFromImage(repo *repository, image *imageapi.Image) (ManifestHandler, error) {
var (
manifest distribution.Manifest
err error
)
switch image.DockerImageManifestMediaType {
case "", schema1.MediaTypeManifest:
manifest, err = unmarshalManifestSchema1([]byte(image.DockerImageManifest), image.DockerImageSignatures)
case schema2.MediaTypeManifest:
manifest, err = unmarshalManifestSchema2([]byte(image.DockerImageManifest))
default:
return nil, fmt.Errorf("unsupported manifest media type %s", image.DockerImageManifestMediaType)
}
if err != nil {
return nil, err
}
return NewManifestHandler(repo, manifest)
}