Signed-off-by: buddhamagnet <buddhamagnet@gmail.com>
| ... | ... |
@@ -20,25 +20,38 @@ import ( |
| 20 | 20 |
"github.com/docker/docker/registry" |
| 21 | 21 |
) |
| 22 | 22 |
|
| 23 |
+// DockerCli represents the docker command line client. |
|
| 24 |
+// Instances of the client can be returned from NewDockerCli. |
|
| 23 | 25 |
type DockerCli struct {
|
| 24 |
- proto string |
|
| 25 |
- addr string |
|
| 26 |
+ // proto holds the client protocol i.e. unix. |
|
| 27 |
+ proto string |
|
| 28 |
+ // addr holds the client address. |
|
| 29 |
+ addr string |
|
| 30 |
+ // configFile holds the configuration file (instance of registry.ConfigFile). |
|
| 26 | 31 |
configFile *registry.ConfigFile |
| 27 |
- in io.ReadCloser |
|
| 28 |
- out io.Writer |
|
| 29 |
- err io.Writer |
|
| 30 |
- keyFile string |
|
| 31 |
- tlsConfig *tls.Config |
|
| 32 |
- scheme string |
|
| 33 |
- // inFd holds file descriptor of the client's STDIN, if it's a valid file |
|
| 32 |
+ // in holds the input stream and closer (io.ReadCloser) for the client. |
|
| 33 |
+ in io.ReadCloser |
|
| 34 |
+ // out holds the output stream (io.Writer) for the client. |
|
| 35 |
+ out io.Writer |
|
| 36 |
+ // err holds the error stream (io.Writer) for the client. |
|
| 37 |
+ err io.Writer |
|
| 38 |
+ // keyFile holds the key file as a string. |
|
| 39 |
+ keyFile string |
|
| 40 |
+ // tlsConfig holds the TLS configuration for the client, and will |
|
| 41 |
+ // set the scheme to https in NewDockerCli if present. |
|
| 42 |
+ tlsConfig *tls.Config |
|
| 43 |
+ // scheme holds the scheme of the client i.e. https. |
|
| 44 |
+ scheme string |
|
| 45 |
+ // inFd holds the file descriptor of the client's STDIN (if valid). |
|
| 34 | 46 |
inFd uintptr |
| 35 |
- // outFd holds file descriptor of the client's STDOUT, if it's a valid file |
|
| 47 |
+ // outFd holds file descriptor of the client's STDOUT (if valid). |
|
| 36 | 48 |
outFd uintptr |
| 37 |
- // isTerminalIn describes if client's STDIN is a TTY |
|
| 49 |
+ // isTerminalIn indicates whether the client's STDIN is a TTY |
|
| 38 | 50 |
isTerminalIn bool |
| 39 |
- // isTerminalOut describes if client's STDOUT is a TTY |
|
| 51 |
+ // isTerminalOut dindicates whether the client's STDOUT is a TTY |
|
| 40 | 52 |
isTerminalOut bool |
| 41 |
- transport *http.Transport |
|
| 53 |
+ // transport holds the client transport instance. |
|
| 54 |
+ transport *http.Transport |
|
| 42 | 55 |
} |
| 43 | 56 |
|
| 44 | 57 |
var funcMap = template.FuncMap{
|
| ... | ... |
@@ -125,6 +138,10 @@ func (cli *DockerCli) CheckTtyInput(attachStdin, ttyMode bool) error {
|
| 125 | 125 |
return nil |
| 126 | 126 |
} |
| 127 | 127 |
|
| 128 |
+// NewDockerCli returns a DockerCli instance with IO output and error streams set by in, out and err. |
|
| 129 |
+// The key file, protocol (i.e. unix) and address are passed in as strings, along with the tls.Config. If the tls.Config |
|
| 130 |
+// is set the client scheme will be set to https. |
|
| 131 |
+// The client will be given a 32-second timeout (see https://github.com/docker/docker/pull/8035). |
|
| 128 | 132 |
func NewDockerCli(in io.ReadCloser, out, err io.Writer, keyFile string, proto, addr string, tlsConfig *tls.Config) *DockerCli {
|
| 129 | 133 |
var ( |
| 130 | 134 |
inFd uintptr |
| ... | ... |
@@ -149,15 +166,15 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer, keyFile string, proto, a |
| 149 | 149 |
err = out |
| 150 | 150 |
} |
| 151 | 151 |
|
| 152 |
- // The transport is created here for reuse during the client session |
|
| 152 |
+ // The transport is created here for reuse during the client session. |
|
| 153 | 153 |
tr := &http.Transport{
|
| 154 | 154 |
TLSClientConfig: tlsConfig, |
| 155 | 155 |
} |
| 156 | 156 |
|
| 157 |
- // Why 32? See issue 8035 |
|
| 157 |
+ // Why 32? See https://github.com/docker/docker/pull/8035. |
|
| 158 | 158 |
timeout := 32 * time.Second |
| 159 | 159 |
if proto == "unix" {
|
| 160 |
- // no need in compressing for local communications |
|
| 160 |
+ // No need for compression in local communications. |
|
| 161 | 161 |
tr.DisableCompression = true |
| 162 | 162 |
tr.Dial = func(_, _ string) (net.Conn, error) {
|
| 163 | 163 |
return net.DialTimeout(proto, addr, timeout) |