diff options
| author | KubeEdge Bot <48982446+kubeedge-bot@users.noreply.github.com> | 2022-07-11 19:46:03 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-11 19:46:03 +0800 |
| commit | cb77f7641315334370b092455a5a665be686b900 (patch) | |
| tree | 8755023ae2276cf6a1a8ad836cd3c77e4a0873e1 | |
| parent | Merge pull request #4009 from cl2017/cleanup (diff) | |
| parent | verify vendor and vendor licenses (diff) | |
| download | kubeedge-cb77f7641315334370b092455a5a665be686b900.tar.gz | |
Merge pull request #3972 from vincentgoat/deprecated-dependency
update deprecate dependency
| -rw-r--r-- | cloud/pkg/cloudhub/servers/httpserver/server.go | 35 | ||||
| -rw-r--r-- | edge/test/cloudhub/stub.go | 10 | ||||
| -rw-r--r-- | external-dependency.md | 2 | ||||
| -rw-r--r-- | go.mod | 1 | ||||
| -rw-r--r-- | vendor/modules.txt | 1 |
5 files changed, 23 insertions, 26 deletions
diff --git a/cloud/pkg/cloudhub/servers/httpserver/server.go b/cloud/pkg/cloudhub/servers/httpserver/server.go index c18bf9234..eb4857ae3 100644 --- a/cloud/pkg/cloudhub/servers/httpserver/server.go +++ b/cloud/pkg/cloudhub/servers/httpserver/server.go @@ -29,8 +29,8 @@ import ( "net/http" "strings" + "github.com/emicklei/go-restful" "github.com/golang-jwt/jwt" - "github.com/gorilla/mux" certutil "k8s.io/client-go/util/cert" "k8s.io/klog/v2" @@ -40,9 +40,12 @@ import ( // StartHTTPServer starts the http service func StartHTTPServer() { - router := mux.NewRouter() - router.HandleFunc(constants.DefaultCertURL, edgeCoreClientCert).Methods(http.MethodGet) - router.HandleFunc(constants.DefaultCAURL, getCA).Methods(http.MethodGet) + serverContainer := restful.NewContainer() + ws := new(restful.WebService) + ws.Path("/") + ws.Route(ws.GET(constants.DefaultCertURL).To(edgeCoreClientCert)) + ws.Route(ws.GET(constants.DefaultCAURL).To(getCA)) + serverContainer.Add(ws) addr := fmt.Sprintf("%s:%d", hubconfig.Config.HTTPS.Address, hubconfig.Config.HTTPS.Port) @@ -54,7 +57,7 @@ func StartHTTPServer() { server := &http.Server{ Addr: addr, - Handler: router, + Handler: serverContainer, TLSConfig: &tls.Config{ Certificates: []tls.Certificate{cert}, ClientAuth: tls.RequestClientCert, @@ -64,9 +67,9 @@ func StartHTTPServer() { } // getCA returns the caCertDER -func getCA(w http.ResponseWriter, r *http.Request) { +func getCA(request *restful.Request, response *restful.Response) { caCertDER := hubconfig.Config.Ca - if _, err := w.Write(caCertDER); err != nil { + if _, err := response.Write(caCertDER); err != nil { klog.Errorf("failed to write caCertDER, err: %v", err) } } @@ -81,23 +84,23 @@ func EncodeCertPEM(cert *x509.Certificate) []byte { } // edgeCoreClientCert will verify the certificate of EdgeCore or token then create EdgeCoreCert and return it -func edgeCoreClientCert(w http.ResponseWriter, r *http.Request) { - if cert := r.TLS.PeerCertificates; len(cert) > 0 { +func edgeCoreClientCert(request *restful.Request, response *restful.Response) { + if cert := request.Request.TLS.PeerCertificates; len(cert) > 0 { if err := verifyCert(cert[0]); err != nil { - klog.Errorf("failed to sign the certificate for edgenode: %s, failed to verify the certificate", r.Header.Get(constants.NodeName)) - w.WriteHeader(http.StatusUnauthorized) - if _, err := w.Write([]byte(err.Error())); err != nil { + klog.Errorf("failed to sign the certificate for edgenode: %s, failed to verify the certificate", request.Request.Header.Get(constants.NodeName)) + response.WriteHeader(http.StatusUnauthorized) + if _, err := response.Write([]byte(err.Error())); err != nil { klog.Errorf("failed to write response, err: %v", err) } } else { - signEdgeCert(w, r) + signEdgeCert(response, request.Request) } return } - if verifyAuthorization(w, r) { - signEdgeCert(w, r) + if verifyAuthorization(response, request.Request) { + signEdgeCert(response, request.Request) } else { - klog.Errorf("failed to sign the certificate for edgenode: %s, invalid token", r.Header.Get(constants.NodeName)) + klog.Errorf("failed to sign the certificate for edgenode: %s, invalid token", request.Request.Header.Get(constants.NodeName)) } } diff --git a/edge/test/cloudhub/stub.go b/edge/test/cloudhub/stub.go index 4f4de193a..149b1d4ea 100644 --- a/edge/test/cloudhub/stub.go +++ b/edge/test/cloudhub/stub.go @@ -5,7 +5,6 @@ import ( "io" "net/http" - "github.com/gorilla/mux" "github.com/gorilla/websocket" v1 "k8s.io/api/core/v1" "k8s.io/klog/v2" @@ -113,13 +112,12 @@ func (tm *stubCloudHub) podHandler(w http.ResponseWriter, req *http.Request) { func (tm *stubCloudHub) Start() { defer tm.Cleanup() - router := mux.NewRouter() - router.HandleFunc("/{group_id}/events", tm.serveEvent) // for edge-hub - router.HandleFunc("/pod", tm.podHandler) // for pod test - + mux := http.NewServeMux() + mux.HandleFunc("/{group_id}/events", tm.serveEvent) // for edge-hub + mux.HandleFunc("/pod", tm.podHandler) // for pod test s := http.Server{ Addr: "127.0.0.1:20000", - Handler: router, + Handler: mux, } klog.Info("Start cloud hub service") err := s.ListenAndServe() diff --git a/external-dependency.md b/external-dependency.md index 809d02af7..af96545f6 100644 --- a/external-dependency.md +++ b/external-dependency.md @@ -49,7 +49,6 @@ |gofuzz |Apache License 2.0 | https://github.com/google/gofuzz |uuid |Apache License 2.0 | https://github.com/google/uuid |gnostic |Apache License 2.0 | https://github.com/googleapis/gnostic -|mux |BSD-3-Clause | https://github.com/gorilla/mux |websocket |BSD-3-Clause | https://github.com/gorilla/websocket |golang-lru |MLP-2.0 | https://github.com/hashicorp/golang-lru |gopass |ISC | https://github.com/howeyc/gopass @@ -110,7 +109,6 @@ |k8s.io/kube-openapi | Apache License 2.0 |https://github.com/kubernetes/kube-openapi |k8s.io/kubernetes | Apache License 2.0 |https://github.com/kubernetes/kubernetes |k8s.io/utils | Apache License 2.0 |https://github.com/kubernetes/utils -|paypal/gatt |BSD-3-Clause |https://github.com/paypal/gatt |go-ansiterm |MIT |https://github.com/Azure/go-ansiterm |win_pdh | |https://github.com/JeffAshton/win_pdh |go-winio |MIT |https://github.com/Microsoft/go-winio @@ -22,7 +22,6 @@ require ( github.com/golang/protobuf v1.5.2 github.com/google/cadvisor v0.39.3 github.com/google/uuid v1.2.0 - github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.4.2 github.com/hashicorp/golang-lru v0.5.3 // indirect github.com/kubeedge/beehive v0.0.0 diff --git a/vendor/modules.txt b/vendor/modules.txt index 2f719f552..c7350cfc2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -386,7 +386,6 @@ github.com/googleapis/gnostic/extensions github.com/googleapis/gnostic/jsonschema github.com/googleapis/gnostic/openapiv2 # github.com/gorilla/mux v1.8.0 -## explicit github.com/gorilla/mux # github.com/gorilla/websocket v1.4.2 ## explicit |
