cmd/dockerd: un-export config methods, and don't pass flags "twice"
- un-export `daemonOptions.InstallFlags()`; `daemonOptions` itself isn't exported, not exported, and `InstallFlags()` isn't matching any interface and only used internally. - un-export `daemonOptions.SetDefaultOptions()` and remove the `flags` argument as we were passing `daemonOptions.flags` as argument on a method attached to `daemonOptions`, which was somewhat backwards. While at it, also removing an intermediate variable that wasn't needed. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
390c7d6871
commit
d9d0683862
5 changed files with 18 additions and 19 deletions
|
@ -75,7 +75,7 @@ func NewDaemonCli() *DaemonCli {
|
|||
}
|
||||
|
||||
func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
||||
opts.SetDefaultOptions(opts.flags)
|
||||
opts.setDefaultOptions()
|
||||
|
||||
if cli.Config, err = loadDaemonCliConfig(opts); err != nil {
|
||||
return err
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
func defaultOptions(t *testing.T, configFile string) *daemonOptions {
|
||||
opts := newDaemonOptions(&config.Config{})
|
||||
opts.flags = &pflag.FlagSet{}
|
||||
opts.InstallFlags(opts.flags)
|
||||
opts.installFlags(opts.flags)
|
||||
if err := installConfigFlags(opts.daemonConfig, opts.flags); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ func newDaemonCommand() (*cobra.Command, error) {
|
|||
}
|
||||
flags.StringVar(&opts.configFile, "config-file", defaultDaemonConfigFile, "Daemon configuration file")
|
||||
configureCertsDir()
|
||||
opts.InstallFlags(flags)
|
||||
opts.installFlags(flags)
|
||||
if err := installConfigFlags(opts.daemonConfig, flags); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -51,8 +51,8 @@ func newDaemonOptions(config *config.Config) *daemonOptions {
|
|||
}
|
||||
}
|
||||
|
||||
// InstallFlags adds flags for the common options on the FlagSet
|
||||
func (o *daemonOptions) InstallFlags(flags *pflag.FlagSet) {
|
||||
// installFlags adds flags for the common options on the FlagSet
|
||||
func (o *daemonOptions) installFlags(flags *pflag.FlagSet) {
|
||||
if dockerCertPath == "" {
|
||||
// cliconfig.Dir returns $DOCKER_CONFIG or ~/.docker.
|
||||
// cliconfig.Dir does not look up $XDG_CONFIG_HOME
|
||||
|
@ -77,18 +77,18 @@ func (o *daemonOptions) InstallFlags(flags *pflag.FlagSet) {
|
|||
flags.VarP(hostOpt, "host", "H", "Daemon socket(s) to connect to")
|
||||
}
|
||||
|
||||
// SetDefaultOptions sets default values for options after flag parsing is
|
||||
// setDefaultOptions sets default values for options after flag parsing is
|
||||
// complete
|
||||
func (o *daemonOptions) SetDefaultOptions(flags *pflag.FlagSet) {
|
||||
func (o *daemonOptions) setDefaultOptions() {
|
||||
// Regardless of whether the user sets it to true or false, if they
|
||||
// specify --tlsverify at all then we need to turn on TLS
|
||||
// TLSVerify can be true even if not set due to DOCKER_TLS_VERIFY env var, so we need
|
||||
// to check that here as well
|
||||
if flags.Changed(FlagTLSVerify) || o.TLSVerify {
|
||||
if o.flags.Changed(FlagTLSVerify) || o.TLSVerify {
|
||||
o.TLS = true
|
||||
}
|
||||
|
||||
if o.TLS && !flags.Changed(FlagTLSVerify) {
|
||||
if o.TLS && !o.flags.Changed(FlagTLSVerify) {
|
||||
// Enable tls verification unless explicitly disabled
|
||||
o.TLSVerify = true
|
||||
}
|
||||
|
@ -96,19 +96,18 @@ func (o *daemonOptions) SetDefaultOptions(flags *pflag.FlagSet) {
|
|||
if !o.TLS {
|
||||
o.TLSOptions = nil
|
||||
} else {
|
||||
tlsOptions := o.TLSOptions
|
||||
tlsOptions.InsecureSkipVerify = !o.TLSVerify
|
||||
o.TLSOptions.InsecureSkipVerify = !o.TLSVerify
|
||||
|
||||
// Reset CertFile and KeyFile to empty string if the user did not specify
|
||||
// the respective flags and the respective default files were not found.
|
||||
if !flags.Changed("tlscert") {
|
||||
if _, err := os.Stat(tlsOptions.CertFile); os.IsNotExist(err) {
|
||||
tlsOptions.CertFile = ""
|
||||
if !o.flags.Changed("tlscert") {
|
||||
if _, err := os.Stat(o.TLSOptions.CertFile); os.IsNotExist(err) {
|
||||
o.TLSOptions.CertFile = ""
|
||||
}
|
||||
}
|
||||
if !flags.Changed("tlskey") {
|
||||
if _, err := os.Stat(tlsOptions.KeyFile); os.IsNotExist(err) {
|
||||
tlsOptions.KeyFile = ""
|
||||
if !o.flags.Changed("tlskey") {
|
||||
if _, err := os.Stat(o.TLSOptions.KeyFile); os.IsNotExist(err) {
|
||||
o.TLSOptions.KeyFile = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
func TestCommonOptionsInstallFlags(t *testing.T) {
|
||||
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
||||
opts := newDaemonOptions(&config.Config{})
|
||||
opts.InstallFlags(flags)
|
||||
opts.installFlags(flags)
|
||||
|
||||
err := flags.Parse([]string{
|
||||
"--tlscacert=/foo/cafile",
|
||||
|
@ -34,7 +34,7 @@ func defaultPath(filename string) string {
|
|||
func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) {
|
||||
flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
|
||||
opts := newDaemonOptions(&config.Config{})
|
||||
opts.InstallFlags(flags)
|
||||
opts.installFlags(flags)
|
||||
|
||||
err := flags.Parse([]string{})
|
||||
assert.Check(t, err)
|
||||
|
|
Loading…
Add table
Reference in a new issue