Add common HTTP client to Azure SD (#9267)
* Add `proxy_url` option to Azure SD Signed-off-by: Levi Harrison <git@leviharrison.dev>
This commit is contained in:
		
							parent
							
								
									3458e338c6
								
							
						
					
					
						commit
						89a6ebd799
					
				|  | @ -565,6 +565,7 @@ var expectedConf = &Config{ | |||
| 					AuthenticationMethod: "OAuth", | ||||
| 					RefreshInterval:      model.Duration(5 * time.Minute), | ||||
| 					Port:                 9100, | ||||
| 					HTTPClientConfig:     config.DefaultHTTPClientConfig, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
|  |  | |||
|  | @ -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 | ||||
| } | ||||
|  |  | |||
|  | @ -429,6 +429,42 @@ subscription_id: <string> | |||
| # The port to scrape metrics from. If using the public IP address, this must | ||||
| # instead be specified in the relabeling rule. | ||||
| [ port: <int> | 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: <string> ] | ||||
|   [ password: <secret> ] | ||||
|   [ password_file: <string> ] | ||||
| 
 | ||||
| # Optional `Authorization` header configuration, currently not supported by Azure. | ||||
| authorization: | ||||
|   # Sets the authentication type. | ||||
|   [ type: <string> | default: Bearer ] | ||||
|   # Sets the credentials. It is mutually exclusive with | ||||
|   # `credentials_file`. | ||||
|   [ credentials: <secret> ] | ||||
|   # Sets the credentials to the credentials read from the configured file. | ||||
|   # It is mutually exclusive with `credentials`. | ||||
|   [ credentials_file: <filename> ] | ||||
| 
 | ||||
| # Optional OAuth 2.0 configuration, currently not supported by Azure. | ||||
| oauth2: | ||||
|   [ <oauth2> ] | ||||
| 
 | ||||
| # Optional proxy URL. | ||||
| [ proxy_url: <string> ] | ||||
| 
 | ||||
| # Configure whether HTTP requests follow HTTP 3xx redirects. | ||||
| [ follow_redirects: <bool> | default = true ] | ||||
| 
 | ||||
| # TLS configuration. | ||||
| tls_config: | ||||
|   [ <tls_config> ] | ||||
| ``` | ||||
| 
 | ||||
| ### `<consul_sd_config>` | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue