Skip to content

Commit

Permalink
Merge pull request #171 from endophage/url_matching
Browse files Browse the repository at this point in the history
can't be so restrictive on notary's GUN matching in URLs
  • Loading branch information
aaronlehmann committed Jul 31, 2015
2 parents ed14cf2 + efda503 commit 1c4d74e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
13 changes: 6 additions & 7 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 23 additions & 1 deletion utils/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand All @@ -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)
}

0 comments on commit 1c4d74e

Please sign in to comment.