2014-11-11 03:57:38 +01:00
|
|
|
package registry
|
|
|
|
|
|
|
|
import (
|
2014-12-09 22:38:07 +01:00
|
|
|
"encoding/json"
|
2014-11-11 03:57:38 +01:00
|
|
|
"net/http"
|
|
|
|
|
2014-12-10 06:25:54 +01:00
|
|
|
"github.com/docker/docker-registry/api/errors"
|
2014-12-09 22:38:07 +01:00
|
|
|
"github.com/docker/docker-registry/storage"
|
2014-11-11 03:57:38 +01:00
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2014-12-09 22:38:07 +01:00
|
|
|
type tagsAPIResponse struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
}
|
|
|
|
|
2014-11-11 03:57:38 +01:00
|
|
|
// GetTags returns a json list of tags for a specific image name.
|
|
|
|
func (th *tagsHandler) GetTags(w http.ResponseWriter, r *http.Request) {
|
2014-12-09 22:38:07 +01:00
|
|
|
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)
|
2014-12-10 06:25:54 +01:00
|
|
|
th.Errors.Push(errors.ErrorCodeNameUnknown, map[string]string{"name": th.Name})
|
2014-12-09 22:38:07 +01:00
|
|
|
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
|
|
|
|
}
|
2014-11-11 03:57:38 +01:00
|
|
|
}
|