Skip to content

Commit

Permalink
add a flag to allow insecureTLSVerify
Browse files Browse the repository at this point in the history
Fixes #62

Signed-off-by: Chmouel Boudjnah <chmouel@chmouel.com>
  • Loading branch information
chmouel committed Mar 2, 2023
1 parent 687ddd8 commit b8ab38d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
22 changes: 14 additions & 8 deletions gosmee/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ accessible endpoint and forward request to your local service`,
decorate = false
}
cfg := goSmee{
smeeURL: smeeURL,
targetURL: targetURL,
saveDir: c.String("saveDir"),
noReplay: c.Bool("noReplay"),
decorate: decorate,
ignoreEvents: c.StringSlice("ignore-event"),
channel: c.String("channel"),
targetCnxTimeout: c.Int("target-connection-timeout"),
smeeURL: smeeURL,
targetURL: targetURL,
saveDir: c.String("saveDir"),
noReplay: c.Bool("noReplay"),
decorate: decorate,
ignoreEvents: c.StringSlice("ignore-event"),
channel: c.String("channel"),
targetCnxTimeout: c.Int("target-connection-timeout"),
insecureTLSVerify: c.Bool("insecure-skip-tls-verify"),
}
err := cfg.clientSetup()
return err
Expand Down Expand Up @@ -137,6 +138,11 @@ accessible endpoint and forward request to your local service`,
Usage: "Disable color output, automatically disabled when non tty",
EnvVars: []string{"NO_COLOR"},
},
&cli.BoolFlag{
Name: "insecure-skip-tls-verify",
Value: false,
Usage: "If true, the target server's certificate will not be checked for validity. This will make your HTTPS connections insecure",
},
},
},
{
Expand Down
5 changes: 4 additions & 1 deletion gosmee/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gosmee

import (
"context"
"crypto/tls"
"encoding/base64"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -41,6 +42,7 @@ type goSmee struct {
ignoreEvents []string
channel string
targetCnxTimeout int
insecureTLSVerify bool
}

type payloadMsg struct {
Expand Down Expand Up @@ -233,7 +235,8 @@ func (c goSmee) replayData(b []byte) error {

ctx, cancel := context.WithTimeout(context.Background(), time.Duration(c.targetCnxTimeout)*time.Second)
defer cancel()
client := http.Client{}
//nolint: gosec
client := http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: !c.insecureTLSVerify}}}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.targetURL, strings.NewReader(string(pm.body)))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion gosmee/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var (
//go:embed templates/index.tmpl
var indexTmpl []byte

func errorIt(w http.ResponseWriter, r *http.Request, status int, err error) {
func errorIt(w http.ResponseWriter, _ *http.Request, status int, err error) {
w.WriteHeader(status)
_, _ = w.Write([]byte(err.Error()))
}
Expand Down

0 comments on commit b8ab38d

Please sign in to comment.