Plugins JSON spec.
Allow full configuration of external plugins via a JSON document. Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
b4f6e2c8b7
commit
7312c4b8bb
6 changed files with 145 additions and 43 deletions
|
@ -5,12 +5,13 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/pkg/sockets"
|
||||
"github.com/docker/docker/pkg/tlsconfig"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -18,11 +19,18 @@ const (
|
|||
defaultTimeOut = 30
|
||||
)
|
||||
|
||||
func NewClient(addr string) *Client {
|
||||
func NewClient(addr string, tlsConfig tlsconfig.Options) (*Client, error) {
|
||||
tr := &http.Transport{}
|
||||
|
||||
c, err := tlsconfig.Client(tlsConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tr.TLSClientConfig = c
|
||||
|
||||
protoAndAddr := strings.Split(addr, "://")
|
||||
configureTCPTransport(tr, protoAndAddr[0], protoAndAddr[1])
|
||||
return &Client{&http.Client{Transport: tr}, protoAndAddr[1]}
|
||||
sockets.ConfigureTCPTransport(tr, protoAndAddr[0], protoAndAddr[1])
|
||||
return &Client{&http.Client{Transport: tr}, protoAndAddr[1]}, nil
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
|
@ -96,18 +104,3 @@ func backoff(retries int) time.Duration {
|
|||
func abort(start time.Time, timeOff time.Duration) bool {
|
||||
return timeOff+time.Since(start) > time.Duration(defaultTimeOut)*time.Second
|
||||
}
|
||||
|
||||
func configureTCPTransport(tr *http.Transport, proto, addr string) {
|
||||
// Why 32? See https://github.com/docker/docker/pull/8035.
|
||||
timeout := 32 * time.Second
|
||||
if proto == "unix" {
|
||||
// No need for compression in local communications.
|
||||
tr.DisableCompression = true
|
||||
tr.Dial = func(_, _ string) (net.Conn, error) {
|
||||
return net.DialTimeout(proto, addr, timeout)
|
||||
}
|
||||
} else {
|
||||
tr.Proxy = http.ProxyFromEnvironment
|
||||
tr.Dial = (&net.Dialer{Timeout: timeout}).Dial
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue