From 2fb815dc3716f297870f63e3624eb473bfa3ddda Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Tue, 12 Apr 2016 13:51:05 -0400 Subject: [PATCH 1/2] notifier: Add proxy parameter to webhook notifier --- config.example.yaml | 3 +++ notifier/notifiers/webhook.go | 25 ++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/config.example.yaml b/config.example.yaml index b489b97e3b..166141116a 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -72,3 +72,6 @@ clair: cafile: keyfile: certfile: + + # Optional HTTP Proxy: must be a valid URL (including the scheme). + proxy: diff --git a/notifier/notifiers/webhook.go b/notifier/notifiers/webhook.go index 9fa1c65556..e284c94723 100644 --- a/notifier/notifiers/webhook.go +++ b/notifier/notifiers/webhook.go @@ -49,6 +49,7 @@ type WebhookNotifierConfiguration struct { CertFile string KeyFile string CAFile string + Proxy string } func init() { @@ -78,22 +79,32 @@ func (h *WebhookNotifier) Configure(config *config.NotifierConfig) (bool, error) return false, nil } if _, err := url.Parse(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 + // 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 } From 927af43be074584546c3ece5d0cf4c91d8389669 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Tue, 12 Apr 2016 13:52:15 -0400 Subject: [PATCH 2/2] notifier: Verify that the given webhook endpoint is an absolute URL --- notifier/notifiers/webhook.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifier/notifiers/webhook.go b/notifier/notifiers/webhook.go index e284c94723..28b766049d 100644 --- a/notifier/notifiers/webhook.go +++ b/notifier/notifiers/webhook.go @@ -78,7 +78,7 @@ func (h *WebhookNotifier) Configure(config *config.NotifierConfig) (bool, error) if httpConfig.Endpoint == "" { return false, nil } - if _, err := url.Parse(httpConfig.Endpoint); err != nil { + if _, err := url.ParseRequestURI(httpConfig.Endpoint); err != nil { return false, fmt.Errorf("could not parse endpoint URL: %s\n", err) } h.endpoint = httpConfig.Endpoint