|
@@ -1,4 +1,4 @@
|
|
-package flags
|
|
|
|
|
|
+package main
|
|
|
|
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
@@ -6,6 +6,8 @@ import (
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
+ cliconfig "github.com/docker/docker/cli/config"
|
|
|
|
+ "github.com/docker/docker/daemon/config"
|
|
"github.com/docker/docker/opts"
|
|
"github.com/docker/docker/opts"
|
|
"github.com/docker/go-connections/tlsconfig"
|
|
"github.com/docker/go-connections/tlsconfig"
|
|
"github.com/spf13/pflag"
|
|
"github.com/spf13/pflag"
|
|
@@ -27,64 +29,69 @@ var (
|
|
dockerTLSVerify = os.Getenv("DOCKER_TLS_VERIFY") != ""
|
|
dockerTLSVerify = os.Getenv("DOCKER_TLS_VERIFY") != ""
|
|
)
|
|
)
|
|
|
|
|
|
-// CommonOptions are options common to both the client and the daemon.
|
|
|
|
-type CommonOptions struct {
|
|
|
|
- Debug bool
|
|
|
|
- Hosts []string
|
|
|
|
- LogLevel string
|
|
|
|
- TLS bool
|
|
|
|
- TLSVerify bool
|
|
|
|
- TLSOptions *tlsconfig.Options
|
|
|
|
|
|
+type daemonOptions struct {
|
|
|
|
+ version bool
|
|
|
|
+ configFile string
|
|
|
|
+ daemonConfig *config.Config
|
|
|
|
+ flags *pflag.FlagSet
|
|
|
|
+ Debug bool
|
|
|
|
+ Hosts []string
|
|
|
|
+ LogLevel string
|
|
|
|
+ TLS bool
|
|
|
|
+ TLSVerify bool
|
|
|
|
+ TLSOptions *tlsconfig.Options
|
|
}
|
|
}
|
|
|
|
|
|
-// NewCommonOptions returns a new CommonOptions
|
|
|
|
-func NewCommonOptions() *CommonOptions {
|
|
|
|
- return &CommonOptions{}
|
|
|
|
|
|
+// newDaemonOptions returns a new daemonFlags
|
|
|
|
+func newDaemonOptions(config *config.Config) *daemonOptions {
|
|
|
|
+ return &daemonOptions{
|
|
|
|
+ daemonConfig: config,
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// InstallFlags adds flags for the common options on the FlagSet
|
|
// InstallFlags adds flags for the common options on the FlagSet
|
|
-func (commonOpts *CommonOptions) InstallFlags(flags *pflag.FlagSet) {
|
|
|
|
|
|
+func (o *daemonOptions) InstallFlags(flags *pflag.FlagSet) {
|
|
if dockerCertPath == "" {
|
|
if dockerCertPath == "" {
|
|
- dockerCertPath = ConfigurationDir()
|
|
|
|
|
|
+ dockerCertPath = cliconfig.Dir()
|
|
}
|
|
}
|
|
|
|
|
|
- flags.BoolVarP(&commonOpts.Debug, "debug", "D", false, "Enable debug mode")
|
|
|
|
- flags.StringVarP(&commonOpts.LogLevel, "log-level", "l", "info", `Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")`)
|
|
|
|
- flags.BoolVar(&commonOpts.TLS, "tls", false, "Use TLS; implied by --tlsverify")
|
|
|
|
- flags.BoolVar(&commonOpts.TLSVerify, FlagTLSVerify, dockerTLSVerify, "Use TLS and verify the remote")
|
|
|
|
|
|
+ flags.BoolVarP(&o.Debug, "debug", "D", false, "Enable debug mode")
|
|
|
|
+ flags.StringVarP(&o.LogLevel, "log-level", "l", "info", `Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")`)
|
|
|
|
+ flags.BoolVar(&o.TLS, "tls", false, "Use TLS; implied by --tlsverify")
|
|
|
|
+ flags.BoolVar(&o.TLSVerify, FlagTLSVerify, dockerTLSVerify, "Use TLS and verify the remote")
|
|
|
|
|
|
// TODO use flag flags.String("identity"}, "i", "", "Path to libtrust key file")
|
|
// TODO use flag flags.String("identity"}, "i", "", "Path to libtrust key file")
|
|
|
|
|
|
- commonOpts.TLSOptions = &tlsconfig.Options{
|
|
|
|
|
|
+ o.TLSOptions = &tlsconfig.Options{
|
|
CAFile: filepath.Join(dockerCertPath, DefaultCaFile),
|
|
CAFile: filepath.Join(dockerCertPath, DefaultCaFile),
|
|
CertFile: filepath.Join(dockerCertPath, DefaultCertFile),
|
|
CertFile: filepath.Join(dockerCertPath, DefaultCertFile),
|
|
KeyFile: filepath.Join(dockerCertPath, DefaultKeyFile),
|
|
KeyFile: filepath.Join(dockerCertPath, DefaultKeyFile),
|
|
}
|
|
}
|
|
- tlsOptions := commonOpts.TLSOptions
|
|
|
|
|
|
+ tlsOptions := o.TLSOptions
|
|
flags.Var(opts.NewQuotedString(&tlsOptions.CAFile), "tlscacert", "Trust certs signed only by this CA")
|
|
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.CertFile), "tlscert", "Path to TLS certificate file")
|
|
flags.Var(opts.NewQuotedString(&tlsOptions.KeyFile), "tlskey", "Path to TLS key file")
|
|
flags.Var(opts.NewQuotedString(&tlsOptions.KeyFile), "tlskey", "Path to TLS key file")
|
|
|
|
|
|
- hostOpt := opts.NewNamedListOptsRef("hosts", &commonOpts.Hosts, opts.ValidateHost)
|
|
|
|
|
|
+ hostOpt := opts.NewNamedListOptsRef("hosts", &o.Hosts, opts.ValidateHost)
|
|
flags.VarP(hostOpt, "host", "H", "Daemon socket(s) to connect to")
|
|
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
|
|
// complete
|
|
-func (commonOpts *CommonOptions) SetDefaultOptions(flags *pflag.FlagSet) {
|
|
|
|
|
|
+func (o *daemonOptions) SetDefaultOptions(flags *pflag.FlagSet) {
|
|
// Regardless of whether the user sets it to true or false, if they
|
|
// Regardless of whether the user sets it to true or false, if they
|
|
// specify --tlsverify at all then we need to turn on TLS
|
|
// 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
|
|
// TLSVerify can be true even if not set due to DOCKER_TLS_VERIFY env var, so we need
|
|
// to check that here as well
|
|
// to check that here as well
|
|
- if flags.Changed(FlagTLSVerify) || commonOpts.TLSVerify {
|
|
|
|
- commonOpts.TLS = true
|
|
|
|
|
|
+ if flags.Changed(FlagTLSVerify) || o.TLSVerify {
|
|
|
|
+ o.TLS = true
|
|
}
|
|
}
|
|
|
|
|
|
- if !commonOpts.TLS {
|
|
|
|
- commonOpts.TLSOptions = nil
|
|
|
|
|
|
+ if !o.TLS {
|
|
|
|
+ o.TLSOptions = nil
|
|
} else {
|
|
} else {
|
|
- tlsOptions := commonOpts.TLSOptions
|
|
|
|
- tlsOptions.InsecureSkipVerify = !commonOpts.TLSVerify
|
|
|
|
|
|
+ tlsOptions := o.TLSOptions
|
|
|
|
+ tlsOptions.InsecureSkipVerify = !o.TLSVerify
|
|
|
|
|
|
// Reset CertFile and KeyFile to empty string if the user did not specify
|
|
// Reset CertFile and KeyFile to empty string if the user did not specify
|
|
// the respective flags and the respective default files were not found.
|
|
// the respective flags and the respective default files were not found.
|
|
@@ -101,8 +108,8 @@ func (commonOpts *CommonOptions) SetDefaultOptions(flags *pflag.FlagSet) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-// SetLogLevel sets the logrus logging level
|
|
|
|
-func SetLogLevel(logLevel string) {
|
|
|
|
|
|
+// setLogLevel sets the logrus logging level
|
|
|
|
+func setLogLevel(logLevel string) {
|
|
if logLevel != "" {
|
|
if logLevel != "" {
|
|
lvl, err := logrus.ParseLevel(logLevel)
|
|
lvl, err := logrus.ParseLevel(logLevel)
|
|
if err != nil {
|
|
if err != nil {
|