Skip to content

Commit

Permalink
api: fix /v1 router and some status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-M authored and jzelinskie committed Feb 24, 2016
1 parent be9423b commit 6b3f95d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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

Expand Down
2 changes: 1 addition & 1 deletion api/v1/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 2 additions & 0 deletions api/v1/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6b3f95d

Please sign in to comment.