From 5e346aa9f22ee916f9b22aeb344c6a3f34c594f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Tue, 21 Feb 2023 12:10:13 +0100 Subject: [PATCH] config: Forbid to set a user/password without the other --- config.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/config.go b/config.go index c4d0109..cde14b6 100644 --- a/config.go +++ b/config.go @@ -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 {