Skip to content

Commit

Permalink
v2http: remove deprecated /v2/machines path
Browse files Browse the repository at this point in the history
  • Loading branch information
heyitsanthony committed Apr 22, 2017
1 parent 7da4516 commit 2bb3318
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 77 deletions.
36 changes: 9 additions & 27 deletions etcdserver/api/v2http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ import (
)

const (
authPrefix = "/v2/auth"
keysPrefix = "/v2/keys"
deprecatedMachinesPrefix = "/v2/machines"
membersPrefix = "/v2/members"
statsPrefix = "/v2/stats"
varsPath = "/debug/vars"
metricsPath = "/metrics"
healthPath = "/health"
versionPath = "/version"
configPath = "/config"
authPrefix = "/v2/auth"
keysPrefix = "/v2/keys"
membersPrefix = "/v2/members"
statsPrefix = "/v2/stats"
varsPath = "/debug/vars"
metricsPath = "/metrics"
healthPath = "/health"
versionPath = "/version"
configPath = "/config"
)

// NewClientHandler generates a muxed http.Handler with the given parameters to serve etcd client requests.
Expand Down Expand Up @@ -84,10 +83,6 @@ func NewClientHandler(server *etcdserver.EtcdServer, timeout time.Duration) http
clientCertAuthEnabled: server.Cfg.ClientCertAuthEnabled,
}

dmh := &deprecatedMachinesHandler{
cluster: server.Cluster(),
}

sech := &authHandler{
sec: sec,
cluster: server.Cluster(),
Expand All @@ -108,7 +103,6 @@ func NewClientHandler(server *etcdserver.EtcdServer, timeout time.Duration) http
mux.Handle(metricsPath, prometheus.Handler())
mux.Handle(membersPrefix, mh)
mux.Handle(membersPrefix+"/", mh)
mux.Handle(deprecatedMachinesPrefix, dmh)
handleAuth(mux, sech)

return requestLogger(mux)
Expand Down Expand Up @@ -170,18 +164,6 @@ func (h *keysHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}

type deprecatedMachinesHandler struct {
cluster api.Cluster
}

func (h *deprecatedMachinesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if !allowMethod(w, r.Method, "GET", "HEAD") {
return
}
endpoints := h.cluster.ClientURLs()
w.Write([]byte(strings.Join(endpoints, ", ")))
}

type membersHandler struct {
sec auth.Store
server etcdserver.Server
Expand Down
50 changes: 0 additions & 50 deletions etcdserver/api/v2http/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1220,56 +1220,6 @@ func TestWriteEvent(t *testing.T) {
}
}

func TestV2DeprecatedMachinesEndpoint(t *testing.T) {
tests := []struct {
method string
wcode int
}{
{"GET", http.StatusOK},
{"HEAD", http.StatusOK},
{"POST", http.StatusMethodNotAllowed},
}

m := &deprecatedMachinesHandler{cluster: &fakeCluster{}}
s := httptest.NewServer(m)
defer s.Close()

for _, tt := range tests {
req, err := http.NewRequest(tt.method, s.URL+deprecatedMachinesPrefix, nil)
if err != nil {
t.Fatal(err)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatal(err)
}

if resp.StatusCode != tt.wcode {
t.Errorf("StatusCode = %d, expected %d", resp.StatusCode, tt.wcode)
}
}
}

func TestServeMachines(t *testing.T) {
cluster := &fakeCluster{
clientURLs: []string{"http://localhost:8080", "http://localhost:8081", "http://localhost:8082"},
}
writer := httptest.NewRecorder()
req, err := http.NewRequest("GET", "", nil)
if err != nil {
t.Fatal(err)
}
h := &deprecatedMachinesHandler{cluster: cluster}
h.ServeHTTP(writer, req)
w := "http://localhost:8080, http://localhost:8081, http://localhost:8082"
if g := writer.Body.String(); g != w {
t.Errorf("body = %s, want %s", g, w)
}
if writer.Code != http.StatusOK {
t.Errorf("code = %d, want %d", writer.Code, http.StatusOK)
}
}

func TestGetID(t *testing.T) {
tests := []struct {
path string
Expand Down

0 comments on commit 2bb3318

Please sign in to comment.