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:
Aaron Lehmann 2015-07-31 14:53:41 -07:00
commit 1c4d74e746
2 changed files with 29 additions and 8 deletions

View File

@ -8,7 +8,6 @@ import (
"net/http" "net/http"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/distribution/registry/api/v2"
"github.com/docker/distribution/registry/auth" "github.com/docker/distribution/registry/auth"
"github.com/endophage/gotuf/data" "github.com/endophage/gotuf/data"
"github.com/endophage/gotuf/signed" "github.com/endophage/gotuf/signed"
@ -85,12 +84,12 @@ func Run(ctx context.Context, addr, tlsCertFile, tlsKeyFile string, trust signed
r := mux.NewRouter() r := mux.NewRouter()
r.Methods("GET").Path("/v2/").Handler(hand(handlers.MainHandler)) 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("POST").Path("/v2/{imageName:.*}/_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:.*}/_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:.*}/_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("GET").Path("/v2/{imageName:.*}/_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("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{ svr := http.Server{
Addr: addr, Addr: addr,
Handler: r, Handler: r,

View File

@ -7,6 +7,7 @@ import (
"github.com/docker/distribution/registry/api/errcode" "github.com/docker/distribution/registry/api/errcode"
"github.com/docker/distribution/registry/api/v2" "github.com/docker/distribution/registry/api/v2"
"github.com/docker/distribution/registry/auth" "github.com/docker/distribution/registry/auth"
"github.com/docker/notary/errors"
"github.com/endophage/gotuf/signed" "github.com/endophage/gotuf/signed"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"golang.org/x/net/context" "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 { 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) e := errcode.ServeJSON(w, err)
if e != nil { if e != nil {
logrus.Error(e) logrus.Error(e)
} }
return return
} }
logrus.Infof("[Notary Server] 200 %s %s", r.Method, r.URL.Path)
return return
} }
@ -89,3 +105,9 @@ func buildAccessRecords(repo string, actions ...string) []auth.Access {
} }
return requiredAccess 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)
}