From 6b3f95dc0313268e36d9bee5d7ca6482049739e9 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Thu, 28 Jan 2016 15:13:11 -0500 Subject: [PATCH] api: fix /v1 router and some status codes --- api/api.go | 4 +++- api/router.go | 3 ++- api/v1/router.go | 2 +- api/v1/routes.go | 2 ++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/api/api.go b/api/api.go index 9f8bf2fdb4..d65e646b0d 100644 --- a/api/api.go +++ b/api/api.go @@ -23,16 +23,18 @@ import ( "strconv" "time" - "github.com/prometheus/common/log" "github.com/tylerb/graceful" "github.com/coreos/clair/api/context" "github.com/coreos/clair/config" "github.com/coreos/clair/utils" + "github.com/coreos/pkg/capnslog" ) const timeoutResponse = `{"Error":{"Message":"Clair failed to respond within the configured timeout window.","Type":"Timeout"}}` +var log = capnslog.NewPackageLogger("github.com/coreos/clair", "api") + func Run(config *config.APIConfig, ctx *context.RouteContext, st *utils.Stopper) { defer st.End() diff --git a/api/router.go b/api/router.go index 7eab82564f..0b10537659 100644 --- a/api/router.go +++ b/api/router.go @@ -33,7 +33,7 @@ const apiVersionLength = len("v99") func newAPIHandler(ctx *context.RouteContext) http.Handler { router := make(router) - router["v1"] = v1.NewRouter(ctx) + router["/v1"] = v1.NewRouter(ctx) return router } @@ -52,6 +52,7 @@ func (rtr router) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + log.Infof("%s %d %s %s", http.StatusNotFound, r.Method, r.RequestURI, r.RemoteAddr) http.NotFound(w, r) } diff --git a/api/v1/router.go b/api/v1/router.go index 5613dd9326..fe05107343 100644 --- a/api/v1/router.go +++ b/api/v1/router.go @@ -41,7 +41,7 @@ func NewRouter(ctx *context.RouteContext) *httprouter.Router { // Fixes router.POST("/namespaces/:namespaceName/vulnerabilities/:vulnerabilityName/fixes", context.HTTPHandler(postFix, ctx)) - router.GET("/namespaces/:namespaceName/vulnerabilities/:vulernabilityName/fixes", context.HTTPHandler(getFixes, ctx)) + router.GET("/namespaces/:namespaceName/vulnerabilities/:vulnerabilityName/fixes", context.HTTPHandler(getFixes, ctx)) router.PUT("/namespaces/:namespaceName/vulnerabilities/:vulnerabilityName/fixes/:fixName", context.HTTPHandler(putFix, ctx)) router.DELETE("/namespaces/:namespaceName/vulnerabilities/:vulnerabilityName/fixes/:fixName", context.HTTPHandler(deleteFix, ctx)) diff --git a/api/v1/routes.go b/api/v1/routes.go index af8de1c54a..e0bb388ffb 100644 --- a/api/v1/routes.go +++ b/api/v1/routes.go @@ -56,9 +56,11 @@ func postLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx if _, ok := err.(*cerrors.ErrBadRequest); ok { w.WriteHeader(http.StatusBadRequest) writeError(w, err, "BadRequest") + return http.StatusBadRequest } w.WriteHeader(http.StatusInternalServerError) writeError(w, err, "InternalServerError") + return http.StatusInternalServerError } w.WriteHeader(http.StatusCreated)