Browse Source

etcdserver/api/v2http: remove unused parameters

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
Gyuho Lee 7 years ago
parent
commit
8235982f6e

+ 3 - 3
etcdserver/api/v2http/capability.go

@@ -22,10 +22,10 @@ import (
 	"github.com/coreos/etcd/etcdserver/api/v2http/httptypes"
 )
 
-func capabilityHandler(c api.Capability, fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc {
+func authCapabilityHandler(fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
-		if !api.IsCapabilityEnabled(c) {
-			notCapable(w, r, c)
+		if !api.IsCapabilityEnabled(api.AuthCapability) {
+			notCapable(w, r, api.AuthCapability)
 			return
 		}
 		fn(w, r)

+ 1 - 1
etcdserver/api/v2http/client.go

@@ -155,7 +155,7 @@ func (h *keysHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 				plog.Errorf("error writing event (%v)", err)
 			}
 		}
-		reportRequestCompleted(rr, resp, startTime)
+		reportRequestCompleted(rr, startTime)
 	case resp.Watcher != nil:
 		ctx, cancel := context.WithTimeout(context.Background(), defaultWatchTimeout)
 		defer cancel()

+ 5 - 5
etcdserver/api/v2http/client_auth.go

@@ -228,11 +228,11 @@ func writeNoAuth(lg *zap.Logger, w http.ResponseWriter, r *http.Request) {
 }
 
 func handleAuth(mux *http.ServeMux, sh *authHandler) {
-	mux.HandleFunc(authPrefix+"/roles", capabilityHandler(api.AuthCapability, sh.baseRoles))
-	mux.HandleFunc(authPrefix+"/roles/", capabilityHandler(api.AuthCapability, sh.handleRoles))
-	mux.HandleFunc(authPrefix+"/users", capabilityHandler(api.AuthCapability, sh.baseUsers))
-	mux.HandleFunc(authPrefix+"/users/", capabilityHandler(api.AuthCapability, sh.handleUsers))
-	mux.HandleFunc(authPrefix+"/enable", capabilityHandler(api.AuthCapability, sh.enableDisable))
+	mux.HandleFunc(authPrefix+"/roles", authCapabilityHandler(sh.baseRoles))
+	mux.HandleFunc(authPrefix+"/roles/", authCapabilityHandler(sh.handleRoles))
+	mux.HandleFunc(authPrefix+"/users", authCapabilityHandler(sh.baseUsers))
+	mux.HandleFunc(authPrefix+"/users/", authCapabilityHandler(sh.handleUsers))
+	mux.HandleFunc(authPrefix+"/enable", authCapabilityHandler(sh.enableDisable))
 }
 
 func (sh *authHandler) baseRoles(w http.ResponseWriter, r *http.Request) {

+ 18 - 18
etcdserver/api/v2http/client_auth_test.go

@@ -438,8 +438,8 @@ func TestGetUserGrantedWithNonexistingRole(t *testing.T) {
 	}
 }
 
-func mustAuthRequest(method, username, password string) *http.Request {
-	req, err := http.NewRequest(method, "path", strings.NewReader(""))
+func mustAuthRequest(username, password string) *http.Request {
+	req, err := http.NewRequest(http.MethodGet, "path", strings.NewReader(""))
 	if err != nil {
 		panic("Cannot make auth request: " + err.Error())
 	}
@@ -447,8 +447,8 @@ func mustAuthRequest(method, username, password string) *http.Request {
 	return req
 }
 
-func unauthedRequest(method string) *http.Request {
-	req, err := http.NewRequest(method, "path", strings.NewReader(""))
+func unauthedRequest() *http.Request {
+	req, err := http.NewRequest(http.MethodGet, "path", strings.NewReader(""))
 	if err != nil {
 		panic("Cannot make request: " + err.Error())
 	}
@@ -484,7 +484,7 @@ func TestPrefixAccess(t *testing.T) {
 	}{
 		{
 			key: "/foo",
-			req: mustAuthRequest("GET", "root", "good"),
+			req: mustAuthRequest("root", "good"),
 			store: &mockAuthStore{
 				users: map[string]*v2auth.User{
 					"root": {
@@ -506,7 +506,7 @@ func TestPrefixAccess(t *testing.T) {
 		},
 		{
 			key: "/foo",
-			req: mustAuthRequest("GET", "user", "good"),
+			req: mustAuthRequest("user", "good"),
 			store: &mockAuthStore{
 				users: map[string]*v2auth.User{
 					"user": {
@@ -534,7 +534,7 @@ func TestPrefixAccess(t *testing.T) {
 		},
 		{
 			key: "/foo",
-			req: mustAuthRequest("GET", "user", "good"),
+			req: mustAuthRequest("user", "good"),
 			store: &mockAuthStore{
 				users: map[string]*v2auth.User{
 					"user": {
@@ -562,7 +562,7 @@ func TestPrefixAccess(t *testing.T) {
 		},
 		{
 			key: "/foo",
-			req: mustAuthRequest("GET", "user", "bad"),
+			req: mustAuthRequest("user", "bad"),
 			store: &mockAuthStore{
 				users: map[string]*v2auth.User{
 					"user": {
@@ -590,7 +590,7 @@ func TestPrefixAccess(t *testing.T) {
 		},
 		{
 			key: "/foo",
-			req: mustAuthRequest("GET", "user", "good"),
+			req: mustAuthRequest("user", "good"),
 			store: &mockAuthStore{
 				users:   map[string]*v2auth.User{},
 				err:     errors.New("Not the user"),
@@ -659,7 +659,7 @@ func TestPrefixAccess(t *testing.T) {
 		// check access for multiple roles
 		{
 			key: "/foo",
-			req: mustAuthRequest("GET", "user", "good"),
+			req: mustAuthRequest("user", "good"),
 			store: &mockAuthStore{
 				users: map[string]*v2auth.User{
 					"user": {
@@ -815,20 +815,20 @@ func TestUserFromClientCertificate(t *testing.T) {
 	}{
 		{
 			// non tls request
-			req:        unauthedRequest("GET"),
+			req:        unauthedRequest(),
 			userExists: false,
 			store:      witherror,
 		},
 		{
 			// cert with cn of existing user
-			req:        tlsAuthedRequest(unauthedRequest("GET"), "user"),
+			req:        tlsAuthedRequest(unauthedRequest(), "user"),
 			userExists: true,
 			username:   "user",
 			store:      noerror,
 		},
 		{
 			// cert with cn of non-existing user
-			req:        tlsAuthedRequest(unauthedRequest("GET"), "otheruser"),
+			req:        tlsAuthedRequest(unauthedRequest(), "otheruser"),
 			userExists: false,
 			store:      witherror,
 		},
@@ -871,30 +871,30 @@ func TestUserFromBasicAuth(t *testing.T) {
 		{
 			// valid user, valid pass
 			username:   "user",
-			req:        mustAuthRequest("GET", "user", "password"),
+			req:        mustAuthRequest("user", "password"),
 			userExists: true,
 		},
 		{
 			// valid user, bad pass
 			username:   "user",
-			req:        mustAuthRequest("GET", "user", "badpass"),
+			req:        mustAuthRequest("user", "badpass"),
 			userExists: false,
 		},
 		{
 			// valid user, no pass
 			username:   "user",
-			req:        mustAuthRequest("GET", "user", ""),
+			req:        mustAuthRequest("user", ""),
 			userExists: false,
 		},
 		{
 			// missing user
 			username:   "missing",
-			req:        mustAuthRequest("GET", "missing", "badpass"),
+			req:        mustAuthRequest("missing", "badpass"),
 			userExists: false,
 		},
 		{
 			// no basic auth
-			req:        unauthedRequest("GET"),
+			req:        unauthedRequest(),
 			userExists: false,
 		},
 	}

+ 1 - 2
etcdserver/api/v2http/metrics.go

@@ -20,7 +20,6 @@ import (
 
 	"net/http"
 
-	"github.com/coreos/etcd/etcdserver"
 	"github.com/coreos/etcd/etcdserver/api/v2http/httptypes"
 	"github.com/coreos/etcd/etcdserver/etcdserverpb"
 	"github.com/coreos/etcd/etcdserver/v2error"
@@ -64,7 +63,7 @@ func reportRequestReceived(request etcdserverpb.Request) {
 	incomingEvents.WithLabelValues(methodFromRequest(request)).Inc()
 }
 
-func reportRequestCompleted(request etcdserverpb.Request, response etcdserver.Response, startTime time.Time) {
+func reportRequestCompleted(request etcdserverpb.Request, startTime time.Time) {
 	method := methodFromRequest(request)
 	successfulEventsHandlingTime.WithLabelValues(method).Observe(time.Since(startTime).Seconds())
 }