Skip to content

Commit 55aac8c

Browse files
AvnerCohenjmattheis
authored andcommitted
Add environment variable and docs to allow skip TLS verification - Fix #27
1 parent 0c81489 commit 55aac8c

4 files changed

Lines changed: 27 additions & 5 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ Gotify-CLI will search the following paths for a config file:
161161
}
162162
```
163163

164+
## Configuration option
165+
166+
If needed, you can disable SSL handcheck validation using an environment variable:
167+
```
168+
export GOTIFY_SKIP_VERIFY_TLS=True
169+
```
170+
171+
164172
### Dockerfile
165173
The Dockerfile contains the steps necessary to build a new version of the CLI and then run it in
166174
a minimal Alpine container.

command/initialize.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package command
33
import (
44
"bufio"
55
"fmt"
6-
"net/http"
76
"net/url"
87
"os"
98
"strconv"
@@ -34,7 +33,7 @@ func Init() cli.Command {
3433
func doInit(ctx *cli.Context) {
3534
serverURL := inputServerURL()
3635
hr()
37-
token := inputToken(gotify.NewClient(serverURL, &http.Client{}))
36+
token := inputToken(gotify.NewClient(serverURL, utils.CreateHTTPClient()))
3837
hr()
3938

4039
conf := &config.Config{
@@ -224,7 +223,7 @@ func inputServerURL() *url.URL {
224223
}
225224

226225
version, err := utils.SpinLoader("Connecting", func(success chan interface{}, failure chan error) {
227-
client := gotify.NewClient(parsedURL, &http.Client{})
226+
client := gotify.NewClient(parsedURL, utils.CreateHTTPClient())
228227

229228
ver, e := client.Version.GetVersion(nil)
230229
if e == nil {

command/push.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package command
22

33
import (
44
"fmt"
5-
"net/http"
65
"net/url"
76
"os"
87
"strings"
@@ -89,7 +88,8 @@ func doPush(ctx *cli.Context) {
8988
}
9089

9190
func pushMessage(parsedURL *url.URL, token string, msg models.MessageExternal, quiet bool) {
92-
client := gotify.NewClient(parsedURL, &http.Client{})
91+
92+
client := gotify.NewClient(parsedURL, utils.CreateHTTPClient())
9393

9494
params := message.NewCreateMessageParams()
9595
params.Body = &msg

utils/createhttpclient.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package utils
2+
3+
import (
4+
"crypto/tls"
5+
"net/http"
6+
"os"
7+
"strings"
8+
)
9+
10+
func CreateHTTPClient() *http.Client {
11+
skipVerify := strings.ToLower(os.Getenv("GOTIFY_SKIP_VERIFY_TLS")) == "true"
12+
customTransport := http.DefaultTransport.(*http.Transport).Clone()
13+
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: skipVerify}
14+
return &http.Client{Transport: customTransport}
15+
}

0 commit comments

Comments
 (0)