mirror of https://github.com/docker/docs.git
Merge pull request #171 from endophage/url_matching
can't be so restrictive on notary's GUN matching in URLs
This commit is contained in:
commit
1c4d74e746
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/distribution/registry/api/v2"
|
||||
"github.com/docker/distribution/registry/auth"
|
||||
"github.com/endophage/gotuf/data"
|
||||
"github.com/endophage/gotuf/signed"
|
||||
|
@ -85,12 +84,12 @@ func Run(ctx context.Context, addr, tlsCertFile, tlsKeyFile string, trust signed
|
|||
|
||||
r := mux.NewRouter()
|
||||
r.Methods("GET").Path("/v2/").Handler(hand(handlers.MainHandler))
|
||||
r.Methods("POST").Path("/v2/{imageName:" + v2.RepositoryNameRegexp.String() + "}/_trust/tuf/").Handler(hand(handlers.AtomicUpdateHandler, "push", "pull"))
|
||||
r.Methods("GET").Path("/v2/{imageName:" + v2.RepositoryNameRegexp.String() + "}/_trust/tuf/{tufRole:(root|targets|snapshot)}.json").Handler(hand(handlers.GetHandler, "pull"))
|
||||
r.Methods("GET").Path("/v2/{imageName:" + v2.RepositoryNameRegexp.String() + "}/_trust/tuf/timestamp.json").Handler(hand(handlers.GetTimestampHandler, "pull"))
|
||||
r.Methods("GET").Path("/v2/{imageName:" + v2.RepositoryNameRegexp.String() + "}/_trust/tuf/timestamp.key").Handler(hand(handlers.GetTimestampKeyHandler, "push", "pull"))
|
||||
r.Methods("DELETE").Path("/v2/{imageName:" + v2.RepositoryNameRegexp.String() + "}/_trust/tuf/").Handler(hand(handlers.DeleteHandler, "push", "pull"))
|
||||
|
||||
r.Methods("POST").Path("/v2/{imageName:.*}/_trust/tuf/").Handler(hand(handlers.AtomicUpdateHandler, "push", "pull"))
|
||||
r.Methods("GET").Path("/v2/{imageName:.*}/_trust/tuf/{tufRole:(root|targets|snapshot)}.json").Handler(hand(handlers.GetHandler, "pull"))
|
||||
r.Methods("GET").Path("/v2/{imageName:.*}/_trust/tuf/timestamp.json").Handler(hand(handlers.GetTimestampHandler, "pull"))
|
||||
r.Methods("GET").Path("/v2/{imageName:.*}/_trust/tuf/timestamp.key").Handler(hand(handlers.GetTimestampKeyHandler, "push", "pull"))
|
||||
r.Methods("DELETE").Path("/v2/{imageName:.*}/_trust/tuf/").Handler(hand(handlers.DeleteHandler, "push", "pull"))
|
||||
r.Methods("GET", "POST", "PUT", "HEAD", "DELETE").Path("/{other:.*}").Handler(hand(utils.NotFoundHandler))
|
||||
svr := http.Server{
|
||||
Addr: addr,
|
||||
Handler: r,
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/docker/distribution/registry/api/errcode"
|
||||
"github.com/docker/distribution/registry/api/v2"
|
||||
"github.com/docker/distribution/registry/auth"
|
||||
"github.com/docker/notary/errors"
|
||||
"github.com/endophage/gotuf/signed"
|
||||
"github.com/gorilla/mux"
|
||||
"golang.org/x/net/context"
|
||||
|
@ -66,13 +67,28 @@ func (root *rootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
if err := root.handler(ctx, w, r); err != nil {
|
||||
logrus.Error("[Notary Server] ", err.Error())
|
||||
if err, ok := err.(errcode.Error); ok {
|
||||
logrus.Errorf(
|
||||
"[Notary Server] %d %s %s",
|
||||
err.Code.Descriptor().HTTPStatusCode,
|
||||
r.Method,
|
||||
r.URL.Path,
|
||||
)
|
||||
} else {
|
||||
logrus.Errorf(
|
||||
"[Notary Server] 5XX %s %s %s",
|
||||
r.Method,
|
||||
r.URL.Path,
|
||||
err.Error(),
|
||||
)
|
||||
}
|
||||
e := errcode.ServeJSON(w, err)
|
||||
if e != nil {
|
||||
logrus.Error(e)
|
||||
}
|
||||
return
|
||||
}
|
||||
logrus.Infof("[Notary Server] 200 %s %s", r.Method, r.URL.Path)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -89,3 +105,9 @@ func buildAccessRecords(repo string, actions ...string) []auth.Access {
|
|||
}
|
||||
return requiredAccess
|
||||
}
|
||||
|
||||
// NotFoundHandler is used as a generic catch all handler to return the ErrMetadataNotFound
|
||||
// 404 response
|
||||
func NotFoundHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
|
||||
return errors.ErrMetadataNotFound.WithDetail(nil)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue