Update Shoutrrr to v0.4 (#810)

This commit is contained in:
nils måsén 2021-03-13 08:58:11 +01:00 committed by GitHub
parent 60a6300f0e
commit 738215a1f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 244 additions and 166 deletions

View file

@ -1,12 +1,11 @@
package notifications
import (
"strings"
shoutrrrTeams "github.com/containrrr/shoutrrr/pkg/services/teams"
t "github.com/containrrr/watchtower/pkg/types"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"net/url"
)
const (
@ -20,11 +19,11 @@ type msTeamsTypeNotifier struct {
}
// NewMsTeamsNotifier is a factory method creating a new teams notifier instance
func NewMsTeamsNotifier(cmd *cobra.Command, acceptedLogLevels []log.Level) t.ConvertableNotifier {
func NewMsTeamsNotifier(cmd *cobra.Command, acceptedLogLevels []log.Level) t.ConvertibleNotifier {
return newMsTeamsNotifier(cmd, acceptedLogLevels)
}
func newMsTeamsNotifier(cmd *cobra.Command, acceptedLogLevels []log.Level) t.ConvertableNotifier {
func newMsTeamsNotifier(cmd *cobra.Command, acceptedLogLevels []log.Level) t.ConvertibleNotifier {
flags := cmd.PersistentFlags()
@ -43,26 +42,19 @@ func newMsTeamsNotifier(cmd *cobra.Command, acceptedLogLevels []log.Level) t.Con
return n
}
func (n *msTeamsTypeNotifier) GetURL() string {
baseURL := "https://outlook.office.com/webhook/"
path := strings.Replace(n.webHookURL, baseURL, "", 1)
rawToken := strings.Replace(path, "/IncomingWebhook", "", 1)
token := strings.Split(rawToken, "/")
config := &shoutrrrTeams.Config{
Token: shoutrrrTeams.Token{
A: token[0],
B: token[1],
C: token[2],
},
func (n *msTeamsTypeNotifier) GetURL() (string, error) {
webhookURL, err := url.Parse(n.webHookURL)
if err != nil {
return "", err
}
return config.GetURL().String()
}
config, err := shoutrrrTeams.ConfigFromWebhookURL(*webhookURL)
if err != nil {
return "", err
}
func (n *msTeamsTypeNotifier) StartNotification() {}
func (n *msTeamsTypeNotifier) SendNotification() {}
func (n *msTeamsTypeNotifier) Close() {}
func (n *msTeamsTypeNotifier) Levels() []log.Level { return nil }
func (n *msTeamsTypeNotifier) Fire(entry *log.Entry) error { return nil }
config.Color = ColorHex
config.Title = GetTitle()
return config.GetURL().String(), nil
}