From d45fc23abfa77fc09fd4561d8826e7155a409476 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 30 Jul 2015 11:23:09 -0700 Subject: [PATCH] Installs a friendly handler for coordinate endpoints when coordinates are disabled. --- command/agent/coordinate_endpoint.go | 8 ++++++++ command/agent/http.go | 3 +++ 2 files changed, 11 insertions(+) diff --git a/command/agent/coordinate_endpoint.go b/command/agent/coordinate_endpoint.go index 21fd3b093d..29a204d6ea 100644 --- a/command/agent/coordinate_endpoint.go +++ b/command/agent/coordinate_endpoint.go @@ -5,6 +5,14 @@ import ( "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 // raw network coordinates. func (s *HTTPServer) CoordinateDatacenters(resp http.ResponseWriter, req *http.Request) (interface{}, error) { diff --git a/command/agent/http.go b/command/agent/http.go index 548aab8565..6174ba2cd8 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -209,6 +209,9 @@ func (s *HTTPServer) registerHandlers(enableDebug bool) { if !s.agent.config.DisableCoordinates { s.mux.HandleFunc("/v1/coordinate/datacenters", s.wrap(s.CoordinateDatacenters)) 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))