Installs a friendly handler for coordinate endpoints when coordinates are disabled.

This commit is contained in:
James Phillips 2015-07-30 11:23:09 -07:00
parent ce0e9759f8
commit d45fc23abf
2 changed files with 11 additions and 0 deletions

View File

@ -5,6 +5,14 @@ import (
"net/http" "net/http"
) )
// coordinateDisabled handles all the endpoints when coordinates are not enabled,
// returning an error message.
func coordinateDisabled(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
resp.WriteHeader(401)
resp.Write([]byte("Coordinate support disabled"))
return nil, nil
}
// CoordinateDatacenters returns the WAN nodes in each datacenter, along with // CoordinateDatacenters returns the WAN nodes in each datacenter, along with
// raw network coordinates. // raw network coordinates.
func (s *HTTPServer) CoordinateDatacenters(resp http.ResponseWriter, req *http.Request) (interface{}, error) { func (s *HTTPServer) CoordinateDatacenters(resp http.ResponseWriter, req *http.Request) (interface{}, error) {

View File

@ -209,6 +209,9 @@ func (s *HTTPServer) registerHandlers(enableDebug bool) {
if !s.agent.config.DisableCoordinates { if !s.agent.config.DisableCoordinates {
s.mux.HandleFunc("/v1/coordinate/datacenters", s.wrap(s.CoordinateDatacenters)) s.mux.HandleFunc("/v1/coordinate/datacenters", s.wrap(s.CoordinateDatacenters))
s.mux.HandleFunc("/v1/coordinate/nodes", s.wrap(s.CoordinateNodes)) s.mux.HandleFunc("/v1/coordinate/nodes", s.wrap(s.CoordinateNodes))
} else {
s.mux.HandleFunc("/v1/coordinate/datacenters", s.wrap(coordinateDisabled))
s.mux.HandleFunc("/v1/coordinate/nodes", s.wrap(coordinateDisabled))
} }
s.mux.HandleFunc("/v1/health/node/", s.wrap(s.HealthNodeChecks)) s.mux.HandleFunc("/v1/health/node/", s.wrap(s.HealthNodeChecks))