From 8498b96a2b210847ec2eb3517700151461144657 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Sun, 3 Sep 2023 22:59:17 +0200 Subject: [PATCH] HTTP SD: Validate HTTP config Fixes #12762 Signed-off-by: Julien Pivotto --- config/config_test.go | 4 ++++ config/testdata/http_token_file.bad.yml | 6 ++++++ discovery/http/http.go | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 config/testdata/http_token_file.bad.yml diff --git a/config/config_test.go b/config/config_test.go index d3288cc90..9698bab13 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1857,6 +1857,10 @@ var expectedErrors = []struct { filename: "http_url_no_host.bad.yml", errMsg: "host is missing in URL", }, + { + filename: "http_token_file.bad.yml", + errMsg: "at most one of bearer_token & bearer_token_file must be configured", + }, { filename: "http_url_bad_scheme.bad.yml", errMsg: "URL scheme must be 'http' or 'https'", diff --git a/config/testdata/http_token_file.bad.yml b/config/testdata/http_token_file.bad.yml new file mode 100644 index 000000000..b3d7a35c9 --- /dev/null +++ b/config/testdata/http_token_file.bad.yml @@ -0,0 +1,6 @@ +scrape_configs: + - job_name: foo + http_sd_configs: + - url: http://foo + bearer_token: foo + bearer_token_file: foo diff --git a/discovery/http/http.go b/discovery/http/http.go index ec958c614..2980d7efd 100644 --- a/discovery/http/http.go +++ b/discovery/http/http.go @@ -99,7 +99,7 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { if parsedURL.Host == "" { return fmt.Errorf("host is missing in URL") } - return nil + return c.HTTPClientConfig.Validate() } const httpSDURLLabel = model.MetaLabelPrefix + "url"