mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-14 06:06:38 +01:00
Update Shoutrrr to v0.4 (#810)
This commit is contained in:
parent
60a6300f0e
commit
738215a1f7
10 changed files with 244 additions and 166 deletions
|
|
@ -1,11 +1,8 @@
|
|||
package notifications
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/containrrr/shoutrrr/pkg/format"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
shoutrrrSmtp "github.com/containrrr/shoutrrr/pkg/services/smtp"
|
||||
|
|
@ -29,11 +26,11 @@ type emailTypeNotifier struct {
|
|||
}
|
||||
|
||||
// NewEmailNotifier is a factory method creating a new email notifier instance
|
||||
func NewEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.ConvertableNotifier {
|
||||
func NewEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.ConvertibleNotifier {
|
||||
return newEmailNotifier(c, acceptedLogLevels)
|
||||
}
|
||||
|
||||
func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.ConvertableNotifier {
|
||||
func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.ConvertibleNotifier {
|
||||
flags := c.PersistentFlags()
|
||||
|
||||
from, _ := flags.GetString("notification-email-from")
|
||||
|
|
@ -63,7 +60,7 @@ func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Convert
|
|||
return n
|
||||
}
|
||||
|
||||
func (e *emailTypeNotifier) GetURL() string {
|
||||
func (e *emailTypeNotifier) GetURL() (string, error) {
|
||||
conf := &shoutrrrSmtp.Config{
|
||||
FromAddress: e.From,
|
||||
FromName: "Watchtower",
|
||||
|
|
@ -73,43 +70,29 @@ func (e *emailTypeNotifier) GetURL() string {
|
|||
Subject: e.getSubject(),
|
||||
Username: e.User,
|
||||
Password: e.Password,
|
||||
UseStartTLS: true,
|
||||
UseStartTLS: !e.tlsSkipVerify,
|
||||
UseHTML: false,
|
||||
Encryption: shoutrrrSmtp.EncMethods.Auto,
|
||||
Auth: shoutrrrSmtp.AuthTypes.None,
|
||||
}
|
||||
|
||||
pkr := format.NewPropKeyResolver(conf)
|
||||
var err error
|
||||
if len(e.User) > 0 {
|
||||
err = pkr.Set("auth", "Plain")
|
||||
} else {
|
||||
err = pkr.Set("auth", "None")
|
||||
conf.Auth = shoutrrrSmtp.AuthTypes.Plain
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Could not set auth type for email notifier: %v", err)
|
||||
if e.tlsSkipVerify {
|
||||
conf.Encryption = shoutrrrSmtp.EncMethods.None
|
||||
}
|
||||
|
||||
return conf.GetURL().String()
|
||||
return conf.GetURL().String(), nil
|
||||
}
|
||||
|
||||
func (e *emailTypeNotifier) getSubject() string {
|
||||
var emailSubject string
|
||||
subject := GetTitle()
|
||||
|
||||
if e.SubjectTag == "" {
|
||||
emailSubject = "Watchtower updates"
|
||||
} else {
|
||||
emailSubject = e.SubjectTag + " Watchtower updates"
|
||||
if e.SubjectTag != "" {
|
||||
subject = e.SubjectTag + " " + subject
|
||||
}
|
||||
if hostname, err := os.Hostname(); err == nil {
|
||||
emailSubject += " on " + hostname
|
||||
}
|
||||
return emailSubject
|
||||
|
||||
return subject
|
||||
}
|
||||
|
||||
// TODO: Delete these once all notifiers have been converted to shoutrrr
|
||||
func (e *emailTypeNotifier) StartNotification() {}
|
||||
func (e *emailTypeNotifier) SendNotification() {}
|
||||
func (e *emailTypeNotifier) Levels() []log.Level { return nil }
|
||||
func (e *emailTypeNotifier) Fire(entry *log.Entry) error { return nil }
|
||||
|
||||
func (e *emailTypeNotifier) Close() {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue