Add transport field to EndpointConfig struct

The EndpointConfig struct in the notifications package has some config
fields for a notification endpoint. This commit adds the ability to pass
in an *http.Transport to use when notifying that endpoint of an event.
This is especially useful for endpoints that use self-signed CAs.

Signed-off-by: Josh Chorlton <josh.chorlton@docker.com>
This commit is contained in:
Josh Chorlton 2016-07-09 12:59:05 -07:00
parent 4e17ab5d31
commit a62f212544
3 changed files with 42 additions and 6 deletions

View file

@ -12,6 +12,7 @@ type EndpointConfig struct {
Timeout time.Duration
Threshold int
Backoff time.Duration
Transport *http.Transport
}
// defaults set any zero-valued fields to a reasonable default.
@ -27,6 +28,10 @@ func (ec *EndpointConfig) defaults() {
if ec.Backoff <= 0 {
ec.Backoff = time.Second
}
if ec.Transport == nil {
ec.Transport = http.DefaultTransport.(*http.Transport)
}
}
// Endpoint is a reliable, queued, thread-safe sink that notify external http
@ -54,7 +59,7 @@ func NewEndpoint(name, url string, config EndpointConfig) *Endpoint {
// Configures the inmemory queue, retry, http pipeline.
endpoint.Sink = newHTTPSink(
endpoint.url, endpoint.Timeout, endpoint.Headers,
endpoint.metrics.httpStatusListener())
endpoint.Transport, endpoint.metrics.httpStatusListener())
endpoint.Sink = newRetryingSink(endpoint.Sink, endpoint.Threshold, endpoint.Backoff)
endpoint.Sink = newEventQueue(endpoint.Sink, endpoint.metrics.eventQueueListener())