support command line parameters for tls
This commit is contained in:
parent
56ab2b992b
commit
8053390d93
3 changed files with 27 additions and 10 deletions
5
cli.go
5
cli.go
|
@ -7,7 +7,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type GlobalOptions struct {
|
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
|
var globalOptions GlobalOptions
|
||||||
|
|
|
@ -53,6 +53,9 @@ func (x *ImagesCommand) Execute(args []string) error {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
client, err := connect()
|
client, err := connect()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
clientImages, err := client.ListImages(docker.ListImagesOptions{All: true})
|
clientImages, err := client.ListImages(docker.ListImagesOptions{All: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
15
util.go
15
util.go
|
@ -1,10 +1,11 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/fsouza/go-dockerclient"
|
"errors"
|
||||||
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
"github.com/fsouza/go-dockerclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
func connect() (*docker.Client, error) {
|
func connect() (*docker.Client, error) {
|
||||||
|
@ -17,6 +18,8 @@ func connect() (*docker.Client, error) {
|
||||||
|
|
||||||
var client *docker.Client
|
var client *docker.Client
|
||||||
var err error
|
var err error
|
||||||
|
dockerTlsVerifyEnv := os.Getenv("DOCKER_TLS_VERIFY")
|
||||||
|
if dockerTlsVerifyEnv == "1" || globalOptions.TLSVerify {
|
||||||
if dockerCertPath := os.Getenv("DOCKER_CERT_PATH"); len(dockerCertPath) > 0 {
|
if dockerCertPath := os.Getenv("DOCKER_CERT_PATH"); len(dockerCertPath) > 0 {
|
||||||
cert := path.Join(dockerCertPath, "cert.pem")
|
cert := path.Join(dockerCertPath, "cert.pem")
|
||||||
key := path.Join(dockerCertPath, "key.pem")
|
key := path.Join(dockerCertPath, "key.pem")
|
||||||
|
@ -25,6 +28,14 @@ func connect() (*docker.Client, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
} else {
|
||||||
client, err = docker.NewClient(endpoint)
|
client, err = docker.NewClient(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue