Skip to content

Commit

Permalink
Ensure backwards compatibility for http proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
akrantz01 committed Apr 28, 2022
1 parent 280ca70 commit 9a6e425
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
20 changes: 9 additions & 11 deletions plugins/common/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,21 @@ import (
)

type HTTPProxy struct {
UseProxy bool `toml:"use_proxy"`
HTTPProxyURL string `toml:"http_proxy_url"`
UseSystemProxy bool `toml:"use_system_proxy"`
HTTPProxyURL string `toml:"http_proxy_url"`
}

type proxyFunc func(req *http.Request) (*url.URL, error)

func (p *HTTPProxy) Proxy() (proxyFunc, error) {
if p.UseProxy {
if len(p.HTTPProxyURL) > 0 {
address, err := url.Parse(p.HTTPProxyURL)
if err != nil {
return nil, fmt.Errorf("error parsing proxy url %q: %w", p.HTTPProxyURL, err)
}
return http.ProxyURL(address), nil
}

if p.UseSystemProxy {
return http.ProxyFromEnvironment, nil
} else if len(p.HTTPProxyURL) > 0 {
address, err := url.Parse(p.HTTPProxyURL)
if err != nil {
return nil, fmt.Errorf("error parsing proxy url %q: %w", p.HTTPProxyURL, err)
}
return http.ProxyURL(address), nil
}

return nil, nil
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/cloudwatch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ API endpoint. In the following order the plugin will attempt to authenticate.
# endpoint_url = ""

## Set http_proxy
# use_proxy = true
# use_system_proxy = false
# http_proxy_url = "http://localhost:8888"

# The minimum period for Cloudwatch metrics is 1 minute (60s). However not all
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/cloudwatch/cloudwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ func TestUpdateWindow(t *testing.T) {
func TestProxyFunction(t *testing.T) {
c := &CloudWatch{
HTTPProxy: proxy.HTTPProxy{
HTTPProxyURL: "http://www.penguins.com",
UseProxy: true,
HTTPProxyURL: "http://www.penguins.com",
UseSystemProxy: true,
},
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/datadog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This plugin writes to the [Datadog Metrics API][metrics] and requires an
# url = "https://app.datadoghq.com/api/v1/series"

## Set http_proxy
# use_proxy = true
# use_system_proxy = false
# http_proxy_url = "http://localhost:8888"

## Override the default (none) compression used to send data.
Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/websocket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ It can output data in any of the [supported output formats](https://github.com/i
# socks5_password = "pass123"

## Optional HTTP proxy to use
# use_proxy = true
# use_system_proxy = false
# http_proxy_url = "http://localhost:8888"

## Data format to output.
Expand Down

0 comments on commit 9a6e425

Please sign in to comment.