mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-14 06:06:38 +01:00
Adds the option to skip TLS verification for a Gotify instance (#544)
This commit is contained in:
parent
10fd81a2c1
commit
dccdf708a9
4 changed files with 33 additions and 12 deletions
|
|
@ -18,7 +18,7 @@ func init() {
|
|||
lock <- true
|
||||
}
|
||||
|
||||
// SetupHTTPUpdates configures the endopint needed for triggering updates via http
|
||||
// SetupHTTPUpdates configures the endpoint needed for triggering updates via http
|
||||
func SetupHTTPUpdates(apiToken string, updateFunction func()) error {
|
||||
if apiToken == "" {
|
||||
return errors.New("api token is empty or has not been set. not starting api")
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package notifications
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
|
@ -17,9 +18,10 @@ const (
|
|||
)
|
||||
|
||||
type gotifyTypeNotifier struct {
|
||||
gotifyURL string
|
||||
gotifyAppToken string
|
||||
logLevels []log.Level
|
||||
gotifyURL string
|
||||
gotifyAppToken string
|
||||
gotifyInsecureSkipVerify bool
|
||||
logLevels []log.Level
|
||||
}
|
||||
|
||||
func newGotifyNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifier {
|
||||
|
|
@ -39,10 +41,13 @@ func newGotifyNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifi
|
|||
log.Fatal("Required argument --notification-gotify-token(cli) or WATCHTOWER_NOTIFICATION_GOTIFY_TOKEN(env) is empty.")
|
||||
}
|
||||
|
||||
gotifyInsecureSkipVerify, _ := flags.GetBool("notification-gotify-tls-skip-verify")
|
||||
|
||||
n := &gotifyTypeNotifier{
|
||||
gotifyURL: gotifyURL,
|
||||
gotifyAppToken: gotifyToken,
|
||||
logLevels: acceptedLogLevels,
|
||||
gotifyURL: gotifyURL,
|
||||
gotifyAppToken: gotifyToken,
|
||||
gotifyInsecureSkipVerify: gotifyInsecureSkipVerify,
|
||||
logLevels: acceptedLogLevels,
|
||||
}
|
||||
|
||||
log.AddHook(n)
|
||||
|
|
@ -79,8 +84,16 @@ func (n *gotifyTypeNotifier) Fire(entry *log.Entry) error {
|
|||
return
|
||||
}
|
||||
|
||||
// Explicitly define the client so we can set InsecureSkipVerify to the desired value.
|
||||
client := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: n.gotifyInsecureSkipVerify,
|
||||
},
|
||||
},
|
||||
}
|
||||
jsonBodyBuffer := bytes.NewBuffer([]byte(jsonBody))
|
||||
resp, err := http.Post(n.getURL(), "application/json", jsonBodyBuffer)
|
||||
resp, err := client.Post(n.getURL(), "application/json", jsonBodyBuffer)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to send Gotify notification: ", err)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue