Skip to content

Commit

Permalink
close tikv#4490: add teset
Browse files Browse the repository at this point in the history
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
  • Loading branch information
CabinfeverB committed Dec 28, 2021
1 parent f4b62fe commit c6e2b8c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 68 deletions.
32 changes: 32 additions & 0 deletions pkg/apiutil/apiutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@ import (
)

var (
<<<<<<< HEAD
// componentSignatureKey is used for http request header key
// to identify component signature
componentSignatureKey = "component"
// componentAnonymousValue identifies anonymous request source
componentAnonymousValue = "anonymous"
=======
// ComponentSignatureKey is used for http request header key
// to identify component signature
ComponentSignatureKey = "ti-component"
// ComponentAnonymousValue identify anonymous request source
ComponentAnonymousValue = "anonymous"
>>>>>>> baa5163b (close #4490: add teset)
)

// DeferClose captures the error returned from closing (if an error occurs).
Expand Down Expand Up @@ -136,17 +144,27 @@ func ErrorResp(rd *render.Render, w http.ResponseWriter, err error) {
}
}
<<<<<<< HEAD
<<<<<<< HEAD

<<<<<<< HEAD
// GetComponentNameOnHTTP returns component name from Request Header
func GetComponentNameOnHTTP(r *http.Request) string {
componentName := r.Header.Get(componentSignatureKey)
if len(componentName) == 0 {
componentName = componentAnonymousValue
=======

// GetComponentNameOnHTTP return component name from Request Header
func GetComponentNameOnHTTP(r *http.Request) string {
componentName := r.Header.Get(ComponentSignatureKey)
if componentName == "" {
componentName = ComponentAnonymousValue
>>>>>>> baa5163b (close #4490: add teset)
}
return componentName
}

<<<<<<< HEAD
// ComponentSignatureRoundTripper is used to add component signature in HTTP header
type ComponentSignatureRoundTripper struct {
proxied http.RoundTripper
Expand Down Expand Up @@ -181,3 +199,17 @@ func GetHTTPRouteName(req *http.Request) (string, bool) {
}
=======
>>>>>>> 45b95d82 (Revert "close #4373 : add framework")
=======
type UserSignatureRoundTripper struct {
Proxied http.RoundTripper
Component string
}

// RoundTrip is used to implement RoundTripper
func (rt *UserSignatureRoundTripper) RoundTrip(req *http.Request) (resp *http.Response, err error) {
req.Header.Add(ComponentSignatureKey, rt.Component)
// Send the request, get the response and the error
resp, err = rt.Proxied.RoundTrip(req)
return
}
>>>>>>> baa5163b (close #4490: add teset)
59 changes: 0 additions & 59 deletions tests/pdctl/global.go

This file was deleted.

19 changes: 10 additions & 9 deletions tools/pd-ctl/pdctl/command/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import (
"github.com/pingcap/errors"
"github.com/spf13/cobra"
"github.com/tikv/pd/pkg/apiutil"
<<<<<<< HEAD
"go.etcd.io/etcd/pkg/transport"
=======
>>>>>>> baa5163b (close #4490: add teset)
)

var (
Expand All @@ -39,19 +42,17 @@ var (

// InitHTTPSClient creates https client with ca file
func InitHTTPSClient(caPath, certPath, keyPath string) error {
tlsInfo := transport.TLSInfo{
CertFile: certPath,
KeyFile: keyPath,
TrustedCAFile: caPath,
}
tlsConfig, err := tlsInfo.ClientConfig()
if err != nil {
return errors.WithStack(err)
}

dialClient = &http.Client{
<<<<<<< HEAD
Transport: apiutil.NewComponentSignatureRoundTripper(
&http.Transport{TLSClientConfig: tlsConfig}, &pdControllerComponentName),
=======
Transport: &apiutil.UserSignatureRoundTripper{
Component: "pdctl",
Proxied: http.DefaultTransport,
},
>>>>>>> baa5163b (close #4490: add teset)
}

return nil
Expand Down

0 comments on commit c6e2b8c

Please sign in to comment.