X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/fd50115d7e01a595f65e47dd95b129362d18e975..f49e418e217e3dcfcfc01b267fe45e2fed09030c:/services/keepstore/handlers.go diff --git a/services/keepstore/handlers.go b/services/keepstore/handlers.go index 5e85ed6216..0a540f58e6 100644 --- a/services/keepstore/handlers.go +++ b/services/keepstore/handlers.go @@ -29,6 +29,7 @@ import ( "github.com/gorilla/mux" + "git.curoverse.com/arvados.git/sdk/go/health" "git.curoverse.com/arvados.git/sdk/go/httpserver" log "github.com/Sirupsen/logrus" ) @@ -78,8 +79,10 @@ func MakeRESTRouter() *router { // Untrash moves blocks from trash back into store rest.HandleFunc(`/untrash/{hash:[0-9a-f]{32}}`, UntrashHandler).Methods("PUT") - // Health check ping - rest.HandleFunc(`/_health/ping`, HealthCheckPingHandler).Methods("GET") + rest.Handle("/_health/{check}", &health.Handler{ + Token: theConfig.ManagementToken, + Prefix: "/_health/", + }).Methods("GET") // Any request which does not match any of these routes gets // 400 Bad Request. @@ -620,39 +623,6 @@ func UntrashHandler(resp http.ResponseWriter, req *http.Request) { } } -var pingResponseOK = map[string]string{"health": "OK"} - -// HealthCheckPingHandler processes "GET /_health/ping" requests -func HealthCheckPingHandler(resp http.ResponseWriter, req *http.Request) { - healthCheckDo(resp, req, pingResponseOK) -} - -func healthCheckDo(resp http.ResponseWriter, req *http.Request, v interface{}) { - msg, code := healthCheckAuth(resp, req) - if msg != "" { - http.Error(resp, msg, code) - return - } - - ok, err := json.Marshal(v) - if err != nil { - http.Error(resp, err.Error(), 500) - } - - resp.Write(ok) -} - -func healthCheckAuth(resp http.ResponseWriter, req *http.Request) (string, int) { - if theConfig.ManagementToken == "" { - return "disabled", http.StatusNotFound - } else if h := req.Header.Get("Authorization"); h == "" { - return "authorization required", http.StatusUnauthorized - } else if h != "Bearer "+theConfig.ManagementToken { - return "authorization error", http.StatusForbidden - } - return "", 0 -} - // GetBlock and PutBlock implement lower-level code for handling // blocks by rooting through volumes connected to the local machine. // Once the handler has determined that system policy permits the