Add environment variable and docs to allow skip TLS verification - Fix #27

This commit is contained in:
Avner Cohen
2020-05-20 23:35:56 +03:00
committed by Jannis Mattheis
parent 0c81489742
commit 55aac8cd0f
4 changed files with 27 additions and 5 deletions

View File

@@ -161,6 +161,14 @@ Gotify-CLI will search the following paths for a config file:
}
```
## Configuration option
If needed, you can disable SSL handcheck validation using an environment variable:
```
export GOTIFY_SKIP_VERIFY_TLS=True
```
### Dockerfile
The Dockerfile contains the steps necessary to build a new version of the CLI and then run it in
a minimal Alpine container.

View File

@@ -3,7 +3,6 @@ package command
import (
"bufio"
"fmt"
"net/http"
"net/url"
"os"
"strconv"
@@ -34,7 +33,7 @@ func Init() cli.Command {
func doInit(ctx *cli.Context) {
serverURL := inputServerURL()
hr()
token := inputToken(gotify.NewClient(serverURL, &http.Client{}))
token := inputToken(gotify.NewClient(serverURL, utils.CreateHTTPClient()))
hr()
conf := &config.Config{
@@ -224,7 +223,7 @@ func inputServerURL() *url.URL {
}
version, err := utils.SpinLoader("Connecting", func(success chan interface{}, failure chan error) {
client := gotify.NewClient(parsedURL, &http.Client{})
client := gotify.NewClient(parsedURL, utils.CreateHTTPClient())
ver, e := client.Version.GetVersion(nil)
if e == nil {

View File

@@ -2,7 +2,6 @@ package command
import (
"fmt"
"net/http"
"net/url"
"os"
"strings"
@@ -89,7 +88,8 @@ func doPush(ctx *cli.Context) {
}
func pushMessage(parsedURL *url.URL, token string, msg models.MessageExternal, quiet bool) {
client := gotify.NewClient(parsedURL, &http.Client{})
client := gotify.NewClient(parsedURL, utils.CreateHTTPClient())
params := message.NewCreateMessageParams()
params.Body = &msg

15
utils/createhttpclient.go Normal file
View File

@@ -0,0 +1,15 @@
package utils
import (
"crypto/tls"
"net/http"
"os"
"strings"
)
func CreateHTTPClient() *http.Client {
skipVerify := strings.ToLower(os.Getenv("GOTIFY_SKIP_VERIFY_TLS")) == "true"
customTransport := http.DefaultTransport.(*http.Transport).Clone()
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: skipVerify}
return &http.Client{Transport: customTransport}
}