config: Forbid to set a user/password without the other

This commit is contained in:
Thorben Günther 2023-02-21 12:10:13 +01:00
parent 41fb0f7766
commit 5e346aa9f2
No known key found for this signature in database
GPG key ID: 415CD778D8C5AFED

View file

@ -134,6 +134,11 @@ func readConfig(path string) (*config, error) {
}
}
if (config.Password != "" && config.User == "") ||
(config.Password == "" && config.User != "") {
return nil, errors.New("user and password have to be set together")
}
labelsDir := cfg.Get("labels")
if labelsDir != nil {
d = labelsDir.Children.Get("order")
@ -214,6 +219,11 @@ func readConfig(path string) (*config, error) {
}
}
if (config.ntfy.Password != "" && config.ntfy.User == "") ||
(config.ntfy.Password == "" && config.ntfy.User != "") {
return nil, errors.New("ntfy: user and password have to be set together")
}
d = ntfyDir.Children.Get("access-token")
if d != nil {
if err := d.ParseParams(&config.ntfy.AccessToken); err != nil {
@ -291,6 +301,11 @@ func readConfig(path string) (*config, error) {
}
}
if (config.am.Password != "" && config.am.User == "") ||
(config.am.Password == "" && config.am.User != "") {
return nil, errors.New("alertmanager: user and password have to be set together")
}
d = amDir.Children.Get("url")
if d != nil {
if err := d.ParseParams(&config.am.URL); err != nil {