From e44d5dfb3a09f52b7d3ae510b48daddb8782be4f Mon Sep 17 00:00:00 2001 From: Jayapriya Pai Date: Fri, 8 Sep 2023 12:00:18 +0530 Subject: [PATCH] AZURE SD: Validate HTTP config Related-to #12810 Signed-off-by: Jayapriya Pai --- config/config_test.go | 4 ++++ config/testdata/azure_bearertoken_basicauth.bad.yml | 11 +++++++++++ discovery/azure/azure.go | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 config/testdata/azure_bearertoken_basicauth.bad.yml diff --git a/config/config_test.go b/config/config_test.go index 9698bab13c..5a688c2853 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1769,6 +1769,10 @@ var expectedErrors = []struct { filename: "azure_authentication_method.bad.yml", errMsg: "unknown authentication_type \"invalid\". Supported types are \"OAuth\" or \"ManagedIdentity\"", }, + { + filename: "azure_bearertoken_basicauth.bad.yml", + errMsg: "at most one of basic_auth, oauth2, bearer_token & bearer_token_file must be configured", + }, { filename: "empty_scrape_config.bad.yml", errMsg: "empty or null scrape config section", diff --git a/config/testdata/azure_bearertoken_basicauth.bad.yml b/config/testdata/azure_bearertoken_basicauth.bad.yml new file mode 100644 index 0000000000..1c22ce2e8e --- /dev/null +++ b/config/testdata/azure_bearertoken_basicauth.bad.yml @@ -0,0 +1,11 @@ +scrape_configs: + - job_name: prometheus + azure_sd_configs: + - subscription_id: 11AAAA11-A11A-111A-A111-1111A1111A11 + tenant_id: BBBB222B-B2B2-2B22-B222-2BB2222BB2B2 + client_id: 333333CC-3C33-3333-CCC3-33C3CCCCC33C + client_secret: mysecret + bearer_token: 1234 + basic_auth: + username: user + password: password diff --git a/discovery/azure/azure.go b/discovery/azure/azure.go index 098fbb4c5f..61dfc4b249 100644 --- a/discovery/azure/azure.go +++ b/discovery/azure/azure.go @@ -144,7 +144,7 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { return fmt.Errorf("unknown authentication_type %q. Supported types are %q or %q", c.AuthenticationMethod, authMethodOAuth, authMethodManagedIdentity) } - return nil + return c.HTTPClientConfig.Validate() } type Discovery struct {