Skip to content

Commit 9b9d103

Browse files
committed
cli/flags: remove special quote handling for --tlsXXX flags
This non-standard handling for these options was added in [moby@e4c1f07] and [moby@abe32de] to work around a regression in Docker 1.13 that caused `docker-machine` to fail. Preserving quotes in such cases is expected (and standard behavior), but versions of Docker before 1.13 used a custom "mflag" package for flag parsing, and that package contained custom handling for quotes (added in [moby@0e9c40e]). Given that Docker Machine reached EOL a long time ago and other options, such as `docker context`, have been added to configure the CLI to connect to a specific host (with corresponding TLS configuration), we can remove the special handling for these flags, as it's inconsistent with all other flags, and not worth maintaining for a tool that no longer exists. [moby@e4c1f07]: moby/moby@e4c1f07 [moby@abe32de]: moby/moby@abe32de [moby@0e9c40e]: moby/moby@0e9c40e Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 2e3d021 commit 9b9d103

File tree

2 files changed

+11
-43
lines changed

2 files changed

+11
-43
lines changed

cli/flags/options.go

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,20 @@ func (o *ClientOptions) InstallFlags(flags *pflag.FlagSet) {
110110
if dockerCertPath == "" {
111111
dockerCertPath = configDir
112112
}
113+
o.TLSOptions = &tlsconfig.Options{
114+
CAFile: filepath.Join(dockerCertPath, DefaultCaFile),
115+
CertFile: filepath.Join(dockerCertPath, DefaultCertFile),
116+
KeyFile: filepath.Join(dockerCertPath, DefaultKeyFile),
117+
}
113118

114119
flags.StringVar(&o.ConfigDir, "config", configDir, "Location of client config files")
115120
flags.BoolVarP(&o.Debug, "debug", "D", false, "Enable debug mode")
116121
flags.StringVarP(&o.LogLevel, "log-level", "l", "info", `Set the logging level ("debug", "info", "warn", "error", "fatal")`)
117122
flags.BoolVar(&o.TLS, "tls", dockerTLS, "Use TLS; implied by --tlsverify")
118123
flags.BoolVar(&o.TLSVerify, FlagTLSVerify, dockerTLSVerify, "Use TLS and verify the remote")
119-
120-
o.TLSOptions = &tlsconfig.Options{
121-
CAFile: filepath.Join(dockerCertPath, DefaultCaFile),
122-
CertFile: filepath.Join(dockerCertPath, DefaultCertFile),
123-
KeyFile: filepath.Join(dockerCertPath, DefaultKeyFile),
124-
}
125-
tlsOptions := o.TLSOptions
126-
flags.Var(&quotedString{&tlsOptions.CAFile}, "tlscacert", "Trust certs signed only by this CA")
127-
flags.Var(&quotedString{&tlsOptions.CertFile}, "tlscert", "Path to TLS certificate file")
128-
flags.Var(&quotedString{&tlsOptions.KeyFile}, "tlskey", "Path to TLS key file")
124+
flags.StringVar(&o.TLSOptions.CAFile, "tlscacert", o.TLSOptions.CAFile, "Trust certs signed only by this CA")
125+
flags.StringVar(&o.TLSOptions.CertFile, "tlscert", o.TLSOptions.CertFile, "Path to TLS certificate file")
126+
flags.StringVar(&o.TLSOptions.KeyFile, "tlskey", o.TLSOptions.KeyFile, "Path to TLS key file")
129127

130128
// TODO(thaJeztah): show the default host.
131129
// TODO(thaJeztah): this should be a string, not an "array" as we only allow a single host.
@@ -179,33 +177,3 @@ func SetLogLevel(logLevel string) {
179177
logrus.SetLevel(logrus.InfoLevel)
180178
}
181179
}
182-
183-
type quotedString struct {
184-
value *string
185-
}
186-
187-
func (s *quotedString) Set(val string) error {
188-
*s.value = trimQuotes(val)
189-
return nil
190-
}
191-
192-
func (*quotedString) Type() string {
193-
return "string"
194-
}
195-
196-
func (s *quotedString) String() string {
197-
return *s.value
198-
}
199-
200-
func trimQuotes(value string) string {
201-
if len(value) < 2 {
202-
return value
203-
}
204-
lastIndex := len(value) - 1
205-
for _, char := range []byte{'\'', '"'} {
206-
if value[0] == char && value[lastIndex] == char {
207-
return value[1:lastIndex]
208-
}
209-
}
210-
return value
211-
}

cli/flags/options_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ func TestClientOptionsInstallFlags(t *testing.T) {
1616
opts.InstallFlags(flags)
1717

1818
err := flags.Parse([]string{
19-
"--tlscacert=\"/foo/cafile\"",
20-
"--tlscert=\"/foo/cert\"",
21-
"--tlskey=\"/foo/key\"",
19+
"--tlscacert=/foo/cafile",
20+
"--tlscert=/foo/cert",
21+
"--tlskey=/foo/key",
2222
})
2323
assert.NilError(t, err)
2424
assert.Check(t, is.Equal("/foo/cafile", opts.TLSOptions.CAFile))

0 commit comments

Comments
 (0)