Skip to content
This repository has been archived by the owner on Aug 3, 2021. It is now read-only.

Commit

Permalink
consul: set transport since HTTPClient may be nil
Browse files Browse the repository at this point in the history
  • Loading branch information
mattatcha committed Jun 14, 2017
1 parent ba6c39d commit 8e6db13
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"log"
"net/url"
"strings"
"strconv"
"os"
"strconv"
"strings"

"github.com/gliderlabs/registrator/bridge"
consulapi "github.com/hashicorp/consul/api"
"github.com/hashicorp/go-cleanhttp"
Expand Down Expand Up @@ -34,21 +35,21 @@ func (f *Factory) New(uri *url.URL) bridge.RegistryAdapter {
if uri.Scheme == "consul-unix" {
config.Address = strings.TrimPrefix(uri.String(), "consul-")
} else if uri.Scheme == "consul-tls" {
tlsConfigDesc := &consulapi.TLSConfig {
Address: uri.Host,
CAFile: os.Getenv("CONSUL_CACERT"),
CertFile: os.Getenv("CONSUL_TLSCERT"),
KeyFile: os.Getenv("CONSUL_TLSKEY"),
InsecureSkipVerify: false,
tlsConfigDesc := &consulapi.TLSConfig{
Address: uri.Host,
CAFile: os.Getenv("CONSUL_CACERT"),
CertFile: os.Getenv("CONSUL_TLSCERT"),
KeyFile: os.Getenv("CONSUL_TLSKEY"),
InsecureSkipVerify: false,
}
tlsConfig, err := consulapi.SetupTLSConfig(tlsConfigDesc)
if err != nil {
log.Fatal("Cannot set up Consul TLSConfig", err)
log.Fatal("Cannot set up Consul TLSConfig", err)
}
config.Scheme = "https"
transport := cleanhttp.DefaultPooledTransport()
transport.TLSClientConfig = tlsConfig
config.HttpClient.Transport = transport
config.Transport = transport
config.Address = uri.Host
} else if uri.Host != "" {
config.Address = uri.Host
Expand Down

0 comments on commit 8e6db13

Please sign in to comment.