2014-11-11 03:57:38 +01:00
|
|
|
package registry
|
|
|
|
|
|
|
|
import (
|
2014-11-13 00:26:35 +01:00
|
|
|
"encoding/json"
|
2014-11-11 03:57:38 +01:00
|
|
|
"net/http"
|
|
|
|
|
2014-11-20 03:52:09 +01:00
|
|
|
"github.com/docker/docker-registry/digest"
|
2014-11-11 03:57:38 +01:00
|
|
|
"github.com/gorilla/handlers"
|
|
|
|
)
|
|
|
|
|
2014-11-11 04:58:10 +01:00
|
|
|
// ImageManifest defines the structure of an image manifest
|
|
|
|
type ImageManifest struct {
|
|
|
|
// Name is the name of the image's repository
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
|
|
|
// Tag is the tag of the image specified by this manifest
|
|
|
|
Tag string `json:"tag"`
|
|
|
|
|
|
|
|
// Architecture is the host architecture on which this image is intended to
|
|
|
|
// run
|
|
|
|
Architecture string `json:"architecture"`
|
|
|
|
|
|
|
|
// FSLayers is a list of filesystem layer blobSums contained in this image
|
|
|
|
FSLayers []FSLayer `json:"fsLayers"`
|
|
|
|
|
|
|
|
// History is a list of unstructured historical data for v1 compatibility
|
|
|
|
History []ManifestHistory `json:"history"`
|
|
|
|
|
|
|
|
// SchemaVersion is the image manifest schema that this image follows
|
|
|
|
SchemaVersion int `json:"schemaVersion"`
|
2014-11-13 00:26:35 +01:00
|
|
|
|
|
|
|
// Raw is the byte representation of the ImageManifest, used for signature
|
|
|
|
// verification
|
|
|
|
Raw []byte `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// imageManifest is used to avoid recursion in unmarshaling
|
|
|
|
type imageManifest ImageManifest
|
|
|
|
|
2014-11-18 00:44:07 +01:00
|
|
|
// UnmarshalJSON populates a new ImageManifest struct from JSON data.
|
2014-11-13 00:26:35 +01:00
|
|
|
func (m *ImageManifest) UnmarshalJSON(b []byte) error {
|
|
|
|
var manifest imageManifest
|
|
|
|
err := json.Unmarshal(b, &manifest)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*m = ImageManifest(manifest)
|
|
|
|
m.Raw = b
|
|
|
|
return nil
|
2014-11-11 04:58:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// FSLayer is a container struct for BlobSums defined in an image manifest
|
|
|
|
type FSLayer struct {
|
|
|
|
// BlobSum is the tarsum of the referenced filesystem image layer
|
2014-11-20 03:52:09 +01:00
|
|
|
BlobSum digest.Digest `json:"blobSum"`
|
2014-11-11 04:58:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ManifestHistory stores unstructured v1 compatibility information
|
|
|
|
type ManifestHistory struct {
|
|
|
|
// V1Compatibility is the raw v1 compatibility information
|
|
|
|
V1Compatibility string `json:"v1Compatibility"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checksum is a container struct for an image checksum
|
|
|
|
type Checksum struct {
|
|
|
|
// HashAlgorithm is the algorithm used to compute the checksum
|
|
|
|
// Supported values: md5, sha1, sha256, sha512
|
|
|
|
HashAlgorithm string
|
|
|
|
|
|
|
|
// Sum is the actual checksum value for the given HashAlgorithm
|
|
|
|
Sum string
|
|
|
|
}
|
|
|
|
|
2014-11-11 03:57:38 +01:00
|
|
|
// imageManifestDispatcher takes the request context and builds the
|
|
|
|
// appropriate handler for handling image manifest requests.
|
|
|
|
func imageManifestDispatcher(ctx *Context, r *http.Request) http.Handler {
|
|
|
|
imageManifestHandler := &imageManifestHandler{
|
|
|
|
Context: ctx,
|
|
|
|
Tag: ctx.vars["tag"],
|
|
|
|
}
|
|
|
|
|
|
|
|
imageManifestHandler.log = imageManifestHandler.log.WithField("tag", imageManifestHandler.Tag)
|
|
|
|
|
|
|
|
return handlers.MethodHandler{
|
|
|
|
"GET": http.HandlerFunc(imageManifestHandler.GetImageManifest),
|
|
|
|
"PUT": http.HandlerFunc(imageManifestHandler.PutImageManifest),
|
|
|
|
"DELETE": http.HandlerFunc(imageManifestHandler.DeleteImageManifest),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// imageManifestHandler handles http operations on image manifests.
|
|
|
|
type imageManifestHandler struct {
|
|
|
|
*Context
|
|
|
|
|
|
|
|
Tag string
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetImageManifest fetches the image manifest from the storage backend, if it exists.
|
|
|
|
func (imh *imageManifestHandler) GetImageManifest(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// PutImageManifest validates and stores and image in the registry.
|
|
|
|
func (imh *imageManifestHandler) PutImageManifest(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteImageManifest removes the image with the given tag from the registry.
|
|
|
|
func (imh *imageManifestHandler) DeleteImageManifest(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
}
|