Skip to content

Commit bce66f6

Browse files
Merge pull request #6275 from thaJeztah/28.x_backport_deprecate_quotedstring
[28.x backport] opts: deprecate QuotedString
2 parents 9fc26d4 + 6bfee62 commit bce66f6

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

cli/flags/options.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ func (o *ClientOptions) InstallFlags(flags *pflag.FlagSet) {
9090
KeyFile: filepath.Join(dockerCertPath, DefaultKeyFile),
9191
}
9292
tlsOptions := o.TLSOptions
93-
flags.Var(opts.NewQuotedString(&tlsOptions.CAFile), "tlscacert", "Trust certs signed only by this CA")
94-
flags.Var(opts.NewQuotedString(&tlsOptions.CertFile), "tlscert", "Path to TLS certificate file")
95-
flags.Var(opts.NewQuotedString(&tlsOptions.KeyFile), "tlskey", "Path to TLS key file")
93+
flags.Var(&quotedString{&tlsOptions.CAFile}, "tlscacert", "Trust certs signed only by this CA")
94+
flags.Var(&quotedString{&tlsOptions.CertFile}, "tlscert", "Path to TLS certificate file")
95+
flags.Var(&quotedString{&tlsOptions.KeyFile}, "tlskey", "Path to TLS key file")
9696

9797
// opts.ValidateHost is not used here, so as to allow connection helpers
9898
hostOpt := opts.NewNamedListOptsRef("hosts", &o.Hosts, nil)
@@ -146,3 +146,33 @@ func SetLogLevel(logLevel string) {
146146
logrus.SetLevel(logrus.InfoLevel)
147147
}
148148
}
149+
150+
type quotedString struct {
151+
value *string
152+
}
153+
154+
func (s *quotedString) Set(val string) error {
155+
*s.value = trimQuotes(val)
156+
return nil
157+
}
158+
159+
func (*quotedString) Type() string {
160+
return "string"
161+
}
162+
163+
func (s *quotedString) String() string {
164+
return *s.value
165+
}
166+
167+
func trimQuotes(value string) string {
168+
if len(value) < 2 {
169+
return value
170+
}
171+
lastIndex := len(value) - 1
172+
for _, char := range []byte{'\'', '"'} {
173+
if value[0] == char && value[lastIndex] == char {
174+
return value[1:lastIndex]
175+
}
176+
}
177+
return value
178+
}

opts/quotedstring.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package opts
22

33
// QuotedString is a string that may have extra quotes around the value. The
44
// quotes are stripped from the value.
5+
//
6+
// Deprecated: This option type is no longer used and will be removed in the next release.
57
type QuotedString struct {
68
value *string
79
}
@@ -35,6 +37,8 @@ func trimQuotes(value string) string {
3537
}
3638

3739
// NewQuotedString returns a new quoted string option
40+
//
41+
// Deprecated: This option type is no longer used and will be removed in the next release.
3842
func NewQuotedString(value *string) *QuotedString {
3943
return &QuotedString{value: value}
4044
}

0 commit comments

Comments
 (0)