Skip to content

Commit

Permalink
Merge pull request #139 from coreos/webhook_proxy
Browse files Browse the repository at this point in the history
Add proxy parameter to webhook notifier
  • Loading branch information
Quentin-M committed Apr 12, 2016
2 parents 87f28fc + 927af43 commit 8d5a330
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ clair:
cafile:
keyfile:
certfile:

# Optional HTTP Proxy: must be a valid URL (including the scheme).
proxy:
27 changes: 19 additions & 8 deletions notifier/notifiers/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type WebhookNotifierConfiguration struct {
CertFile string
KeyFile string
CAFile string
Proxy string
}

func init() {
Expand Down Expand Up @@ -77,23 +78,33 @@ func (h *WebhookNotifier) Configure(config *config.NotifierConfig) (bool, error)
if httpConfig.Endpoint == "" {
return false, nil
}
if _, err := url.Parse(httpConfig.Endpoint); err != nil {
return false, errors.New("invalid endpoint URL")
if _, err := url.ParseRequestURI(httpConfig.Endpoint); err != nil {
return false, fmt.Errorf("could not parse endpoint URL: %s\n", err)
}
h.endpoint = httpConfig.Endpoint

// Setup HTTP client.
transport := &http.Transport{}
h.client = &http.Client{
Transport: transport,
Timeout: timeout,
}

// Initialize TLS.
tlsConfig, err := loadTLSClientConfig(&httpConfig)
transport.TLSClientConfig, err = loadTLSClientConfig(&httpConfig)
if err != nil {
return false, fmt.Errorf("could not initialize client cert auth: %s\n", err)
}

h.client = &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
},
Timeout: timeout,
// Set proxy.
if httpConfig.Proxy != "" {
proxyURL, err := url.ParseRequestURI(httpConfig.Proxy)
if err != nil {
return false, fmt.Errorf("could not parse proxy URL: %s\n", err)
}
transport.Proxy = http.ProxyURL(proxyURL)
}

return true, nil
}

Expand Down

0 comments on commit 8d5a330

Please sign in to comment.