Merge pull request #139 from coreos/webhook_proxy

Add proxy parameter to webhook notifier
This commit is contained in:
Quentin Machu 2016-04-12 15:02:40 -04:00
commit 8d5a330acf
2 changed files with 22 additions and 8 deletions

View File

@ -72,3 +72,6 @@ clair:
cafile: cafile:
keyfile: keyfile:
certfile: certfile:
# Optional HTTP Proxy: must be a valid URL (including the scheme).
proxy:

View File

@ -49,6 +49,7 @@ type WebhookNotifierConfiguration struct {
CertFile string CertFile string
KeyFile string KeyFile string
CAFile string CAFile string
Proxy string
} }
func init() { func init() {
@ -77,23 +78,33 @@ func (h *WebhookNotifier) Configure(config *config.NotifierConfig) (bool, error)
if httpConfig.Endpoint == "" { if httpConfig.Endpoint == "" {
return false, nil return false, nil
} }
if _, err := url.Parse(httpConfig.Endpoint); err != nil { if _, err := url.ParseRequestURI(httpConfig.Endpoint); err != nil {
return false, errors.New("invalid endpoint URL") return false, fmt.Errorf("could not parse endpoint URL: %s\n", err)
} }
h.endpoint = httpConfig.Endpoint h.endpoint = httpConfig.Endpoint
// Setup HTTP client.
transport := &http.Transport{}
h.client = &http.Client{
Transport: transport,
Timeout: timeout,
}
// Initialize TLS. // Initialize TLS.
tlsConfig, err := loadTLSClientConfig(&httpConfig) transport.TLSClientConfig, err = loadTLSClientConfig(&httpConfig)
if err != nil { if err != nil {
return false, fmt.Errorf("could not initialize client cert auth: %s\n", err) return false, fmt.Errorf("could not initialize client cert auth: %s\n", err)
} }
h.client = &http.Client{ // Set proxy.
Transport: &http.Transport{ if httpConfig.Proxy != "" {
TLSClientConfig: tlsConfig, proxyURL, err := url.ParseRequestURI(httpConfig.Proxy)
}, if err != nil {
Timeout: timeout, return false, fmt.Errorf("could not parse proxy URL: %s\n", err)
} }
transport.Proxy = http.ProxyURL(proxyURL)
}
return true, nil return true, nil
} }