Skip to content

Commit

Permalink
Add an option to skip tls verification in HTTPOverRPC action (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-elinardi authored Oct 18, 2023
1 parent ccf262c commit 5912494
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 66 deletions.
5 changes: 5 additions & 0 deletions services/httpoverrpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ type getCmd struct {
showResponseHeaders bool
protocol string
hostname string
insecureSkipVerify bool
}

func (*getCmd) Name() string { return "get" }
Expand All @@ -226,6 +227,7 @@ func (g *getCmd) SetFlags(f *flag.FlagSet) {
f.Var(&g.headers, "header", "Header to send in the request, may be specified multiple times.")
f.StringVar(&g.body, "body", "", "Body to send in request")
f.BoolVar(&g.showResponseHeaders, "show-response-headers", false, "If true, print response code and headers")
f.BoolVar(&g.insecureSkipVerify, "insecure-skip-tls-verify", false, "If true, skip TLS cert verification")
}

func (g *getCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
Expand Down Expand Up @@ -266,6 +268,9 @@ func (g *getCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface
Port: int32(port),
Protocol: g.protocol,
Hostname: g.hostname,
Tlsconfig: &pb.TLSConfig{
InsecureSkipVerify: g.insecureSkipVerify,
},
}

resp, err := proxy.HostOneMany(ctx, req)
Expand Down
38 changes: 35 additions & 3 deletions services/httpoverrpc/client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,41 @@ var (
)

type HTTPTransporter struct {
conn *proxy.Conn
conn *proxy.Conn
insecureSkipVerify bool
}

func NewHTTPTransporter(conn *proxy.Conn) *HTTPTransporter {
type httpTransporterOptions struct {
insecureSkipVerify bool
}

type Option interface {
apply(*httpTransporterOptions)
}

type optionFunc func(*httpTransporterOptions)

func (o optionFunc) apply(opts *httpTransporterOptions) {
o(opts)
}

func WithInsecureSkipVerify(insecureSkipVerify bool) Option {
return optionFunc(func(o *httpTransporterOptions) {
o.insecureSkipVerify = insecureSkipVerify
})
}

func NewHTTPTransporter(conn *proxy.Conn, opts ...Option) *HTTPTransporter {
options := &httpTransporterOptions{
insecureSkipVerify: false,
}

for _, opt := range opts {
opt.apply(options)
}
return &HTTPTransporter{
conn,
conn: conn,
insecureSkipVerify: options.insecureSkipVerify,
}
}

Expand Down Expand Up @@ -132,6 +161,9 @@ func (c *HTTPTransporter) RoundTrip(req *http.Request) (*http.Response, error) {
},
Protocol: req.URL.Scheme,
Hostname: req.URL.Hostname(),
Tlsconfig: &pb.TLSConfig{
InsecureSkipVerify: c.insecureSkipVerify,
},
}

port, errPort := getPort(req, reqPb.Protocol)
Expand Down
189 changes: 133 additions & 56 deletions services/httpoverrpc/httpoverrpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5912494

Please sign in to comment.