Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(notify): get access_token passwords working for matrix #196

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions notifiers/shoutrrr/shoutrrr.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ func (s *Shoutrrr) GetURL() (url string) {
// matrix://user:password@host[:port][/port]/[?rooms=!roomID1[,roomAlias2]][&disableTLS=yes]
port := s.GetURLField("port")
path := s.GetURLField("path")
user := s.GetURLField("user")
rooms := s.GetParam("rooms")
rooms = util.ValueIfNotDefault(rooms, "?rooms="+rooms)
disableTLS := s.GetParam("disabletls")
Expand All @@ -142,8 +141,8 @@ func (s *Shoutrrr) GetURL() (url string) {
disableTLS = "?" + disableTLS
}
}
url = fmt.Sprintf("matrix://%s%s@%s%s%s/%s%s",
util.ValueIfNotDefault(user, user+":"),
url = fmt.Sprintf("matrix://%s:%s@%s%s%s/%s%s",
s.GetURLField("user"),
s.GetURLField("password"),
s.GetURLField("host"),
util.ValueIfNotDefault(port, ":"+port),
Expand Down Expand Up @@ -297,7 +296,7 @@ func (s *Shoutrrr) Send(
for {
msg := fmt.Sprintf("Sending %q to %q", toSend, url)
jLog.Verbose(msg, logFrom, !jLog.IsLevel("debug"))
jLog.Debug(msg+fmt.Sprintf(" with params=%q", *params), logFrom, jLog.IsLevel("debug"))
jLog.Debug(fmt.Sprintf("%s with params=%q", msg, *params), logFrom, jLog.IsLevel("debug"))
err := sender.Send(toSend, params)

failed := false
Expand Down
2 changes: 1 addition & 1 deletion notifiers/shoutrrr/shoutrrr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestGetURL(t *testing.T) {
urlFields: map[string]string{"host": "HOST", "token": "TOKEN", "username": "USERNAME", "port": "8443"}},
"mattermost - base + port + path": {sType: "mattermost", want: "mattermost://USERNAME@HOST:8443/PATH/TOKEN",
urlFields: map[string]string{"host": "HOST", "token": "TOKEN", "username": "USERNAME", "path": "PATH", "port": "8443"}},
"matrix - base": {sType: "matrix", want: "matrix://PASSWORD@HOST/",
"matrix - base": {sType: "matrix", want: "matrix://:PASSWORD@HOST/",
urlFields: map[string]string{"host": "HOST", "password": "PASSWORD"}},
"matrix - base + user": {sType: "matrix", want: "matrix://USER:PASSWORD@HOST/",
urlFields: map[string]string{"host": "HOST", "password": "PASSWORD", "user": "USER"}},
Expand Down
2 changes: 1 addition & 1 deletion notifiers/shoutrrr/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (s *Shoutrrr) checkValuesMaster(prefix string, errs *error, errsOptions *er
util.ErrorToString(*errsURLFields), prefix)
}
if s.GetURLField("password") == "" {
*errsURLFields = fmt.Errorf("%s%s password: <required> e.g. 'pass123' OR 'access_token'\\",
*errsURLFields = fmt.Errorf("%s%s password: <required> e.g. 'pass123' (with user) OR 'access_token' (no user)\\",
util.ErrorToString(*errsURLFields), prefix)
}
case "opsgenie":
Expand Down
1 change: 1 addition & 0 deletions testing/shoutrrr.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func findShoutrrr(
slice["test"].HardDefaults = &emptyShoutrrs
slice["test"].InitMaps()
slice["test"].Main.InitMaps()
slice["test"].Failed = &map[string]*bool{}

notifyType := slice["test"].GetType()
if cfg.Defaults.Notify[notifyType] != nil {
Expand Down