Skip to content

Commit

Permalink
fix(notify): mattermost username harddefault + error printing
Browse files Browse the repository at this point in the history
- `url_fields.username`, not `params.username`
- fix some errors to show it's in params, not url_fields
- remove internal conversion to `starttls` for email as shoutrrr fixed it
containrrr/shoutrrr#252
  • Loading branch information
JosephKav committed May 30, 2022
1 parent 19f73ae commit a30a259
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ For further help, check out the [Getting Started](https://release-argus.io/docs/

#### Config formatting

The config can be broken down into 6 key areas. ([Further help](https://release-argus.io/docs/config/))
The config can be broken down into 5 key areas. ([Further help](https://release-argus.io/docs/config/))
- [defaults](https://release-argus.io/docs/config/defaults/) - This is broken down into areas with defaults for [services](https://release-argus.io/docs/config/defaults/#service-portion), [notify](https://release-argus.io/docs/config/defaults/#notify-portion) and [webhooks](https://release-argus.io/docs/config/defaults/#webhook-portion).
- [settings](https://release-argus.io/docs/config/settings/) - Settings for the Argus server.
- [service](https://release-argus.io/docs/config/service/) - A dictionary mapping of all the services to monitor as well as what to notify when a new release is found.
Expand Down
4 changes: 2 additions & 2 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ func (d *Defaults) SetDefaults() {
"delay": "0s",
},
URLFields: map[string]string{
"port": "443",
"username": "Argus",
"port": "443",
},
Params: types.Params{"username": "Argus"},
}
d.Notify["mattermost"].InitMaps()
d.Notify["matrix"] = &shoutrrr.Shoutrrr{
Expand Down
19 changes: 4 additions & 15 deletions notifiers/shoutrrr/shoutrrr.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,39 @@ func (s *Shoutrrr) GetParams() (params *shoutrrr_types.Params) {

// Service Params
for key := range s.Params {
cKey := fixParamKey(key)
(*params)[cKey] = s.GetSelfParam(key)
(*params)[key] = s.GetSelfParam(key)
}

// Main Params
for key := range s.Main.Params {
cKey := fixParamKey(key)
_, exist := s.Params[key]
// Only overwrite if it doesn't exist in the level below
if !exist {
(*params)[cKey] = s.Main.GetSelfParam(key)
(*params)[key] = s.Main.GetSelfParam(key)
}
}

// Default Params
for key := range s.Defaults.Params {
cKey := fixParamKey(key)
_, exist := (s.Params)[key]
// Only overwrite if it doesn't exist in the level below
if !exist {
(*params)[cKey] = s.Defaults.GetSelfParam(key)
(*params)[key] = s.Defaults.GetSelfParam(key)
}
}

// HardDefault Params
for key := range s.HardDefaults.Params {
cKey := fixParamKey(key)
_, exist := s.Params[key]
// Only overwrite if it doesn't exist in the level below
if !exist {
(*params)[cKey] = s.HardDefaults.GetSelfParam(key)
(*params)[key] = s.HardDefaults.GetSelfParam(key)
}
}

return
}

func fixParamKey(key string) string {
if key == "usestarttls" {
return "starttls"
}
return key
}

func (s *Shoutrrr) GetURL() (url string) {
switch s.GetType() {
case "discord":
Expand Down
6 changes: 3 additions & 3 deletions notifiers/shoutrrr/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ func (s *Shoutrrr) checkValuesMaster(prefix string, errs *error, errsOptions *er
*errsURLFields = fmt.Errorf("%s%s host: <required> e.g. 'smtp.example.io'\\", utils.ErrorToString(*errsURLFields), prefix)
}
if s.GetParam("fromaddress") == "" {
*errsURLFields = fmt.Errorf("%s%s fromaddress: <required> e.g. '[email protected]'\\", utils.ErrorToString(*errsParams), prefix)
*errsParams = fmt.Errorf("%s%s fromaddress: <required> e.g. '[email protected]'\\", utils.ErrorToString(*errsParams), prefix)
}
if s.GetParam("toaddresses") == "" {
*errsURLFields = fmt.Errorf("%s%s toaddresses: <required> e.g. '[email protected]'\\", utils.ErrorToString(*errsParams), prefix)
*errsParams = fmt.Errorf("%s%s toaddresses: <required> e.g. '[email protected]'\\", utils.ErrorToString(*errsParams), prefix)
}
case "gotify":
// gotify://host:port/path/token
Expand All @@ -182,7 +182,7 @@ func (s *Shoutrrr) checkValuesMaster(prefix string, errs *error, errsOptions *er
*errsURLFields = fmt.Errorf("%s%s webhookid: <required> e.g. 'h1fyLh42h7lDI2L11T-bv'\\", utils.ErrorToString(*errsURLFields), prefix)
}
if s.GetParam("events") == "" {
*errsURLFields = fmt.Errorf("%s%s ebets: <required> e.g. 'event1,event2'\\", utils.ErrorToString(*errsParams), prefix)
*errsParams = fmt.Errorf("%s%s ebets: <required> e.g. 'event1,event2'\\", utils.ErrorToString(*errsParams), prefix)
}
case "join":
// join://apiKey@join
Expand Down
21 changes: 10 additions & 11 deletions testing/shoutrrr.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,20 @@ func TestNotify(flag *string, cfg *config.Config) {
(*shoutrrr)["test"] = &argus_shoutrrr.Shoutrrr{
ID: flag,
Main: cfg.Notify[*flag],
Defaults: cfg.Defaults.Notify["telegram"],
HardDefaults: hardDefaults.Notify["telegram"],
Defaults: &emptyShoutrrs,
HardDefaults: &emptyShoutrrs,
}
(*shoutrrr)["test"].InitMaps()
(*shoutrrr)["test"].Main.InitMaps()
if (*shoutrrr)["test"].Defaults == nil {
(*shoutrrr)["test"].Defaults = &emptyShoutrrs
} else {
(*shoutrrr)["test"].Defaults.InitMaps()
}
if (*shoutrrr)["test"].HardDefaults == nil {
(*shoutrrr)["test"].HardDefaults = &emptyShoutrrs
} else {
(*shoutrrr)["test"].HardDefaults.InitMaps()

notifyType := (*shoutrrr)["test"].GetType()
if cfg.Defaults.Notify[notifyType] != nil {
(*shoutrrr)["test"].Defaults = cfg.Defaults.Notify[notifyType]
}
(*shoutrrr)["test"].Defaults.InitMaps()
(*shoutrrr)["test"].HardDefaults = hardDefaults.Notify[notifyType]
(*shoutrrr)["test"].HardDefaults.InitMaps()

if err := (*shoutrrr)["test"].CheckValues(" "); err != nil {
msg := fmt.Sprintf("notify:\n %s:\n%s\n", *flag, strings.ReplaceAll(err.Error(), "\\", "\n"))
jLog.Fatal(msg, logFrom, true)
Expand Down

0 comments on commit a30a259

Please sign in to comment.