2015-08-21 04:50:15 +00:00
|
|
|
package distribution
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-01-20 17:59:19 +00:00
|
|
|
"mime"
|
2015-08-21 04:50:15 +00:00
|
|
|
|
|
|
|
"github.com/docker/distribution/context"
|
|
|
|
"github.com/docker/distribution/digest"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Manifest represents a registry object specifying a set of
|
|
|
|
// references and an optional target
|
|
|
|
type Manifest interface {
|
|
|
|
// References returns a list of objects which make up this manifest.
|
|
|
|
// The references are strictly ordered from base to head. A reference
|
|
|
|
// is anything which can be represented by a distribution.Descriptor
|
|
|
|
References() []Descriptor
|
|
|
|
|
|
|
|
// Payload provides the serialized format of the manifest, in addition to
|
|
|
|
// the mediatype.
|
|
|
|
Payload() (mediatype string, payload []byte, err error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ManifestBuilder creates a manifest allowing one to include dependencies.
|
|
|
|
// Instances can be obtained from a version-specific manifest package. Manifest
|
|
|
|
// specific data is passed into the function which creates the builder.
|
|
|
|
type ManifestBuilder interface {
|
|
|
|
// Build creates the manifest from his builder.
|
2015-12-10 00:38:04 +00:00
|
|
|
Build(ctx context.Context) (Manifest, error)
|
2015-08-21 04:50:15 +00:00
|
|
|
|
|
|
|
// References returns a list of objects which have been added to this
|
|
|
|
// builder. The dependencies are returned in the order they were added,
|
|
|
|
// which should be from base to head.
|
|
|
|
References() []Descriptor
|
|
|
|
|
|
|
|
// AppendReference includes the given object in the manifest after any
|
|
|
|
// existing dependencies. If the add fails, such as when adding an
|
|
|
|
// unsupported dependency, an error may be returned.
|
|
|
|
AppendReference(dependency Describable) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// ManifestService describes operations on image manifests.
|
|
|
|
type ManifestService interface {
|
|
|
|
// Exists returns true if the manifest exists.
|
|
|
|
Exists(ctx context.Context, dgst digest.Digest) (bool, error)
|
|
|
|
|
|
|
|
// Get retrieves the manifest specified by the given digest
|
|
|
|
Get(ctx context.Context, dgst digest.Digest, options ...ManifestServiceOption) (Manifest, error)
|
|
|
|
|
|
|
|
// Put creates or updates the given manifest returning the manifest digest
|
|
|
|
Put(ctx context.Context, manifest Manifest, options ...ManifestServiceOption) (digest.Digest, error)
|
|
|
|
|
|
|
|
// Delete removes the manifest specified by the given digest. Deleting
|
|
|
|
// a manifest that doesn't exist will return ErrManifestNotFound
|
|
|
|
Delete(ctx context.Context, dgst digest.Digest) error
|
|
|
|
|
|
|
|
// Enumerate fills 'manifests' with the manifests in this service up
|
|
|
|
// to the size of 'manifests' and returns 'n' for the number of entries
|
|
|
|
// which were filled. 'last' contains an offset in the manifest set
|
|
|
|
// and can be used to resume iteration.
|
|
|
|
//Enumerate(ctx context.Context, manifests []Manifest, last Manifest) (n int, err error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Describable is an interface for descriptors
|
|
|
|
type Describable interface {
|
|
|
|
Descriptor() Descriptor
|
|
|
|
}
|
|
|
|
|
|
|
|
// ManifestMediaTypes returns the supported media types for manifests.
|
|
|
|
func ManifestMediaTypes() (mediaTypes []string) {
|
|
|
|
for t := range mappings {
|
2016-01-20 23:22:38 +00:00
|
|
|
if t != "" {
|
|
|
|
mediaTypes = append(mediaTypes, t)
|
|
|
|
}
|
2015-08-21 04:50:15 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalFunc implements manifest unmarshalling a given MediaType
|
|
|
|
type UnmarshalFunc func([]byte) (Manifest, Descriptor, error)
|
|
|
|
|
|
|
|
var mappings = make(map[string]UnmarshalFunc, 0)
|
|
|
|
|
|
|
|
// UnmarshalManifest looks up manifest unmarshall functions based on
|
|
|
|
// MediaType
|
2016-01-18 17:59:50 +00:00
|
|
|
func UnmarshalManifest(ctHeader string, p []byte) (Manifest, Descriptor, error) {
|
2016-01-20 17:59:19 +00:00
|
|
|
// Need to look up by the actual media type, not the raw contents of
|
2016-01-18 17:59:50 +00:00
|
|
|
// the header. Strip semicolons and anything following them.
|
|
|
|
var mediatype string
|
2016-01-20 17:59:19 +00:00
|
|
|
if ctHeader != "" {
|
|
|
|
var err error
|
|
|
|
mediatype, _, err = mime.ParseMediaType(ctHeader)
|
|
|
|
if err != nil {
|
|
|
|
return nil, Descriptor{}, err
|
|
|
|
}
|
2016-01-18 17:59:50 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
unmarshalFunc, ok := mappings[mediatype]
|
|
|
|
if !ok {
|
2016-01-21 17:34:06 +00:00
|
|
|
unmarshalFunc, ok = mappings[""]
|
|
|
|
if !ok {
|
|
|
|
return nil, Descriptor{}, fmt.Errorf("unsupported manifest mediatype and no default available: %s", mediatype)
|
|
|
|
}
|
2015-08-21 04:50:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return unmarshalFunc(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterManifestSchema registers an UnmarshalFunc for a given schema type. This
|
|
|
|
// should be called from specific
|
|
|
|
func RegisterManifestSchema(mediatype string, u UnmarshalFunc) error {
|
|
|
|
if _, ok := mappings[mediatype]; ok {
|
|
|
|
return fmt.Errorf("manifest mediatype registration would overwrite existing: %s", mediatype)
|
|
|
|
}
|
|
|
|
mappings[mediatype] = u
|
|
|
|
return nil
|
|
|
|
}
|