diff --git a/config/config_test.go b/config/config_test.go index 3055de74d8..a6c30b3e5e 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -565,6 +565,7 @@ var expectedConf = &Config{ AuthenticationMethod: "OAuth", RefreshInterval: model.Duration(5 * time.Minute), Port: 9100, + HTTPClientConfig: config.DefaultHTTPClientConfig, }, }, }, diff --git a/discovery/azure/azure.go b/discovery/azure/azure.go index b0de0abd8c..c81eb22053 100644 --- a/discovery/azure/azure.go +++ b/discovery/azure/azure.go @@ -64,6 +64,7 @@ var DefaultSDConfig = SDConfig{ RefreshInterval: model.Duration(5 * time.Minute), Environment: azure.PublicCloud.Name, AuthenticationMethod: authMethodOAuth, + HTTPClientConfig: config_util.DefaultHTTPClientConfig, } func init() { @@ -80,6 +81,8 @@ type SDConfig struct { ClientSecret config_util.Secret `yaml:"client_secret,omitempty"` RefreshInterval model.Duration `yaml:"refresh_interval,omitempty"` AuthenticationMethod string `yaml:"authentication_method,omitempty"` + + HTTPClientConfig config_util.HTTPClientConfig `yaml:",inline"` } // Name returns the name of the Config. @@ -200,19 +203,29 @@ func createAzureClient(cfg SDConfig) (azureClient, error) { } } + client, err := config_util.NewClientFromConfig(cfg.HTTPClientConfig, "azure_sd") + if err != nil { + return azureClient{}, err + } + sender := autorest.DecorateSender(client) + bearerAuthorizer := autorest.NewBearerAuthorizer(spt) c.vm = compute.NewVirtualMachinesClientWithBaseURI(resourceManagerEndpoint, cfg.SubscriptionID) c.vm.Authorizer = bearerAuthorizer + c.vm.Sender = sender c.nic = network.NewInterfacesClientWithBaseURI(resourceManagerEndpoint, cfg.SubscriptionID) c.nic.Authorizer = bearerAuthorizer + c.nic.Sender = sender c.vmss = compute.NewVirtualMachineScaleSetsClientWithBaseURI(resourceManagerEndpoint, cfg.SubscriptionID) c.vmss.Authorizer = bearerAuthorizer + c.vm.Sender = sender c.vmssvm = compute.NewVirtualMachineScaleSetVMsClientWithBaseURI(resourceManagerEndpoint, cfg.SubscriptionID) c.vmssvm.Authorizer = bearerAuthorizer + c.vmssvm.Sender = sender return c, nil } diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 6b451b595c..291b9fe035 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -429,6 +429,42 @@ subscription_id: # The port to scrape metrics from. If using the public IP address, this must # instead be specified in the relabeling rule. [ port: | default = 80 ] + +# Authentication information used to authenticate to the consul server. +# Note that `basic_auth`, `authorization` and `oauth2` options are +# mutually exclusive. +# `password` and `password_file` are mutually exclusive. + +# Optional HTTP basic authentication information, currently not support by Azure. +basic_auth: + [ username: ] + [ password: ] + [ password_file: ] + +# Optional `Authorization` header configuration, currently not supported by Azure. +authorization: + # Sets the authentication type. + [ type: | default: Bearer ] + # Sets the credentials. It is mutually exclusive with + # `credentials_file`. + [ credentials: ] + # Sets the credentials to the credentials read from the configured file. + # It is mutually exclusive with `credentials`. + [ credentials_file: ] + +# Optional OAuth 2.0 configuration, currently not supported by Azure. +oauth2: + [ ] + +# Optional proxy URL. +[ proxy_url: ] + +# Configure whether HTTP requests follow HTTP 3xx redirects. +[ follow_redirects: | default = true ] + +# TLS configuration. +tls_config: + [ ] ``` ### ``