support command line parameters for tls

This commit is contained in:
Nate Jones 2015-05-21 14:33:45 -07:00
parent 56ab2b992b
commit 8053390d93
3 changed files with 27 additions and 10 deletions

5
cli.go
View file

@ -7,7 +7,10 @@ import (
)
type GlobalOptions struct {
// no options yet
TLSCaCert string `long:"tlscacert" value-name:"~/.docker/ca.pem" description:"Trust certs signed only by this CA"`
TLSCert string `long:"tlscert" value-name:"~/.docker/cert.pem" description:"Path to TLS certificate file"`
TLSKey string `long:"tlskey" value-name:"~/.docker/key.pem" description:"Path to TLS key file"`
TLSVerify bool `long:"tlsverify" description:"Use TLS and verify the remote"`
}
var globalOptions GlobalOptions

View file

@ -53,6 +53,9 @@ func (x *ImagesCommand) Execute(args []string) error {
} else {
client, err := connect()
if err != nil {
return err
}
clientImages, err := client.ListImages(docker.ListImagesOptions{All: true})
if err != nil {

15
util.go
View file

@ -1,10 +1,11 @@
package main
import (
"github.com/fsouza/go-dockerclient"
"errors"
"os"
"path"
"github.com/fsouza/go-dockerclient"
)
func connect() (*docker.Client, error) {
@ -17,6 +18,8 @@ func connect() (*docker.Client, error) {
var client *docker.Client
var err error
dockerTlsVerifyEnv := os.Getenv("DOCKER_TLS_VERIFY")
if dockerTlsVerifyEnv == "1" || globalOptions.TLSVerify {
if dockerCertPath := os.Getenv("DOCKER_CERT_PATH"); len(dockerCertPath) > 0 {
cert := path.Join(dockerCertPath, "cert.pem")
key := path.Join(dockerCertPath, "key.pem")
@ -25,6 +28,14 @@ func connect() (*docker.Client, error) {
if err != nil {
return nil, err
}
} else if len(globalOptions.TLSCert) > 0 && len(globalOptions.TLSKey) > 0 && len(globalOptions.TLSCaCert) > 0 {
client, err = docker.NewTLSClient(endpoint, globalOptions.TLSCert, globalOptions.TLSKey, globalOptions.TLSCaCert)
if err != nil {
return nil, err
}
} else {
return nil, errors.New("TLS Verification requested but certs not specified")
}
} else {
client, err = docker.NewClient(endpoint)
if err != nil {