Merge pull request #51 from calavera/load_default_tls_ca

Make sure the TLS CA is properly loaded by default.
This commit is contained in:
David Calavera 2016-01-25 09:28:08 -08:00
Родитель 944a42d783 105be31b63
Коммит 57dd6a77ab
1 изменённых файлов: 10 добавлений и 6 удалений

Просмотреть файл

@ -10,6 +10,8 @@ import (
"path/filepath"
"strings"
"time"
"github.com/docker/go-connections/tlsconfig"
)
// Client is the API client that performs all operations
@ -41,15 +43,17 @@ type Client struct {
func NewEnvClient() (*Client, error) {
var transport *http.Transport
if dockerCertPath := os.Getenv("DOCKER_CERT_PATH"); dockerCertPath != "" {
tlsc := &tls.Config{}
cert, err := tls.LoadX509KeyPair(filepath.Join(dockerCertPath, "cert.pem"), filepath.Join(dockerCertPath, "key.pem"))
options := tlsconfig.Options{
CAFile: filepath.Join(dockerCertPath, "ca.pem"),
CertFile: filepath.Join(dockerCertPath, "cert.pem"),
KeyFile: filepath.Join(dockerCertPath, "key.pem"),
InsecureSkipVerify: os.Getenv("DOCKER_TLS_VERIFY") == "",
}
tlsc, err := tlsconfig.Client(options)
if err != nil {
return nil, fmt.Errorf("Error loading x509 key pair: %s", err)
return nil, err
}
tlsc.Certificates = append(tlsc.Certificates, cert)
tlsc.InsecureSkipVerify = os.Getenv("DOCKER_TLS_VERIFY") == ""
transport = &http.Transport{
TLSClientConfig: tlsc,
}