Skip to content

Commit 93450e5

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 93450e5

File tree

2 files changed

+6
-36
lines changed

2 files changed

+6
-36
lines changed

cli/flags/options.go

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ func (o *ClientOptions) InstallFlags(flags *pflag.FlagSet) {
123123
KeyFile: filepath.Join(dockerCertPath, DefaultKeyFile),
124124
}
125125
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")
126+
flags.StringVar(&tlsOptions.CAFile, "tlscacert", tlsOptions.CAFile, "Trust certs signed only by this CA")
127+
flags.StringVar(&tlsOptions.CertFile, "tlscert", tlsOptions.CertFile, "Path to TLS certificate file")
128+
flags.StringVar(&tlsOptions.KeyFile, "tlskey", tlsOptions.KeyFile, "Path to TLS key file")
129129

130130
// TODO(thaJeztah): show the default host.
131131
// TODO(thaJeztah): this should be a string, not an "array" as we only allow a single host.
@@ -179,33 +179,3 @@ func SetLogLevel(logLevel string) {
179179
logrus.SetLevel(logrus.InfoLevel)
180180
}
181181
}
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)