From 344f9d8d15eeb422f6ea4659de8df0a3d80d84f2 Mon Sep 17 00:00:00 2001 From: Jayapriya Pai Date: Fri, 8 Sep 2023 17:21:17 +0530 Subject: [PATCH] PUPPETDB SD: Validate HTTP config Related-to #12810 Signed-off-by: Jayapriya Pai --- config/config_test.go | 4 ++++ config/testdata/puppetdb_token_file.bad.yml | 7 +++++++ discovery/puppetdb/puppetdb.go | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 config/testdata/puppetdb_token_file.bad.yml diff --git a/config/config_test.go b/config/config_test.go index 6ccc22e84..acba6450e 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1825,6 +1825,10 @@ var expectedErrors = []struct { filename: "puppetdb_no_scheme.bad.yml", errMsg: "URL scheme must be 'http' or 'https'", }, + { + filename: "puppetdb_token_file.bad.yml", + errMsg: "at most one of bearer_token & bearer_token_file must be configured", + }, { filename: "hetzner_role.bad.yml", errMsg: "unknown role", diff --git a/config/testdata/puppetdb_token_file.bad.yml b/config/testdata/puppetdb_token_file.bad.yml new file mode 100644 index 000000000..7775f2d19 --- /dev/null +++ b/config/testdata/puppetdb_token_file.bad.yml @@ -0,0 +1,7 @@ +scrape_configs: +- job_name: puppetdb + puppetdb_sd_configs: + - url: http://puppet + query: 'resources { type = "Package" and title = "httpd" }' + bearer_token: foo + bearer_token_file: foo diff --git a/discovery/puppetdb/puppetdb.go b/discovery/puppetdb/puppetdb.go index f22a2e22b..9484a0aa6 100644 --- a/discovery/puppetdb/puppetdb.go +++ b/discovery/puppetdb/puppetdb.go @@ -115,7 +115,7 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { if c.Query == "" { return fmt.Errorf("query missing") } - return nil + return c.HTTPClientConfig.Validate() } // Discovery provides service discovery functionality based