forked from TrueCloudLab/distribution
7b56d10076
This commit locks down the set of http error codes that will be part of the inital V2 specification, proposed in docker/docker#9015. The naming order has been slightly changed and there are few tweaks to ensure all conditions are captured but this will be set the docker core will be impleemnted against. To support this, the errors have been moved into an api/errors package. A new type, ErrorDescriptor, has been defined to centralize the code, message and definitions used with each type. The information therein can be used to generate documentation and response code mappings (yet to come...). In addition to the refactoring that came along with this change, several tests have been added to ensure serialization round trips are reliable. This allows better support for using these error types on the client and server side. This is coupled with some tweaks in the client code to fix issues with error reporting. Other fixes in the client include moving client-specific errors out of the base package and ensuring that we have correct parameters for finishing uploads.
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package registry
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/docker/docker-registry/api/errors"
|
|
"github.com/docker/docker-registry/storage"
|
|
"github.com/gorilla/handlers"
|
|
)
|
|
|
|
// tagsDispatcher constructs the tags handler api endpoint.
|
|
func tagsDispatcher(ctx *Context, r *http.Request) http.Handler {
|
|
tagsHandler := &tagsHandler{
|
|
Context: ctx,
|
|
}
|
|
|
|
return handlers.MethodHandler{
|
|
"GET": http.HandlerFunc(tagsHandler.GetTags),
|
|
}
|
|
}
|
|
|
|
// tagsHandler handles requests for lists of tags under a repository name.
|
|
type tagsHandler struct {
|
|
*Context
|
|
}
|
|
|
|
type tagsAPIResponse struct {
|
|
Name string `json:"name"`
|
|
Tags []string `json:"tags"`
|
|
}
|
|
|
|
// GetTags returns a json list of tags for a specific image name.
|
|
func (th *tagsHandler) GetTags(w http.ResponseWriter, r *http.Request) {
|
|
defer r.Body.Close()
|
|
manifests := th.services.Manifests()
|
|
|
|
tags, err := manifests.Tags(th.Name)
|
|
if err != nil {
|
|
switch err := err.(type) {
|
|
case storage.ErrUnknownRepository:
|
|
w.WriteHeader(404)
|
|
th.Errors.Push(errors.ErrorCodeNameUnknown, map[string]string{"name": th.Name})
|
|
default:
|
|
th.Errors.PushErr(err)
|
|
}
|
|
return
|
|
}
|
|
|
|
enc := json.NewEncoder(w)
|
|
if err := enc.Encode(tagsAPIResponse{
|
|
Name: th.Name,
|
|
Tags: tags,
|
|
}); err != nil {
|
|
th.Errors.PushErr(err)
|
|
return
|
|
}
|
|
}
|