mirror of https://github.com/docker/cli.git
Trim quotes from TLS flags.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
f2cac1b6e8
commit
fe181a18d5
|
@ -59,11 +59,15 @@ func (commonOpts *CommonOptions) InstallFlags(flags *pflag.FlagSet) {
|
|||
|
||||
// TODO use flag flags.String("identity"}, "i", "", "Path to libtrust key file")
|
||||
|
||||
commonOpts.TLSOptions = &tlsconfig.Options{}
|
||||
commonOpts.TLSOptions = &tlsconfig.Options{
|
||||
CAFile: filepath.Join(dockerCertPath, DefaultCaFile),
|
||||
CertFile: filepath.Join(dockerCertPath, DefaultCertFile),
|
||||
KeyFile: filepath.Join(dockerCertPath, DefaultKeyFile),
|
||||
}
|
||||
tlsOptions := commonOpts.TLSOptions
|
||||
flags.StringVar(&tlsOptions.CAFile, "tlscacert", filepath.Join(dockerCertPath, DefaultCaFile), "Trust certs signed only by this CA")
|
||||
flags.StringVar(&tlsOptions.CertFile, "tlscert", filepath.Join(dockerCertPath, DefaultCertFile), "Path to TLS certificate file")
|
||||
flags.StringVar(&tlsOptions.KeyFile, "tlskey", filepath.Join(dockerCertPath, DefaultKeyFile), "Path to TLS key file")
|
||||
flags.Var(opts.NewQuotedString(&tlsOptions.CAFile), "tlscacert", "Trust certs signed only by this CA")
|
||||
flags.Var(opts.NewQuotedString(&tlsOptions.CertFile), "tlscert", "Path to TLS certificate file")
|
||||
flags.Var(opts.NewQuotedString(&tlsOptions.KeyFile), "tlskey", "Path to TLS key file")
|
||||
|
||||
hostOpt := opts.NewNamedListOptsRef("hosts", &commonOpts.Hosts, opts.ValidateHost)
|
||||
flags.VarP(hostOpt, "host", "H", "Daemon socket(s) to connect to")
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package flags
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
cliconfig "github.com/docker/docker/cli/config"
|
||||
"github.com/docker/docker/pkg/testutil/assert"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
func TestCommonOptionsInstallFlags(t *testing.T) {
|
||||
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
||||
opts := NewCommonOptions()
|
||||
opts.InstallFlags(flags)
|
||||
|
||||
err := flags.Parse([]string{
|
||||
"--tlscacert=\"/foo/cafile\"",
|
||||
"--tlscert=\"/foo/cert\"",
|
||||
"--tlskey=\"/foo/key\"",
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, opts.TLSOptions.CAFile, "/foo/cafile")
|
||||
assert.Equal(t, opts.TLSOptions.CertFile, "/foo/cert")
|
||||
assert.Equal(t, opts.TLSOptions.KeyFile, "/foo/key")
|
||||
}
|
||||
|
||||
func defaultPath(filename string) string {
|
||||
return filepath.Join(cliconfig.Dir(), filename)
|
||||
}
|
||||
|
||||
func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) {
|
||||
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
||||
opts := NewCommonOptions()
|
||||
opts.InstallFlags(flags)
|
||||
|
||||
err := flags.Parse([]string{})
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, opts.TLSOptions.CAFile, defaultPath("ca.pem"))
|
||||
assert.Equal(t, opts.TLSOptions.CertFile, defaultPath("cert.pem"))
|
||||
assert.Equal(t, opts.TLSOptions.KeyFile, defaultPath("key.pem"))
|
||||
}
|
Loading…
Reference in New Issue