mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Make TLSOptions and LogConfig embedded structs.
That way the configuration file becomes flag, without extra keys. Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
ed4038676f
commit
5e80ac0dd1
4 changed files with 36 additions and 32 deletions
|
@ -56,7 +56,6 @@ type CommonConfig struct {
|
||||||
GraphDriver string `json:"storage-driver,omitempty"`
|
GraphDriver string `json:"storage-driver,omitempty"`
|
||||||
GraphOptions []string `json:"storage-opts,omitempty"`
|
GraphOptions []string `json:"storage-opts,omitempty"`
|
||||||
Labels []string `json:"labels,omitempty"`
|
Labels []string `json:"labels,omitempty"`
|
||||||
LogConfig LogConfig `json:"log-config,omitempty"`
|
|
||||||
Mtu int `json:"mtu,omitempty"`
|
Mtu int `json:"mtu,omitempty"`
|
||||||
Pidfile string `json:"pidfile,omitempty"`
|
Pidfile string `json:"pidfile,omitempty"`
|
||||||
Root string `json:"graph,omitempty"`
|
Root string `json:"graph,omitempty"`
|
||||||
|
@ -81,7 +80,11 @@ type CommonConfig struct {
|
||||||
LogLevel string `json:"log-level,omitempty"`
|
LogLevel string `json:"log-level,omitempty"`
|
||||||
TLS bool `json:"tls,omitempty"`
|
TLS bool `json:"tls,omitempty"`
|
||||||
TLSVerify bool `json:"tlsverify,omitempty"`
|
TLSVerify bool `json:"tlsverify,omitempty"`
|
||||||
TLSOptions CommonTLSOptions `json:"tls-opts,omitempty"`
|
|
||||||
|
// Embedded structs that allow config
|
||||||
|
// deserialization without the full struct.
|
||||||
|
CommonTLSOptions
|
||||||
|
LogConfig
|
||||||
|
|
||||||
reloadLock sync.Mutex
|
reloadLock sync.Mutex
|
||||||
valuesSet map[string]interface{}
|
valuesSet map[string]interface{}
|
||||||
|
@ -227,7 +230,8 @@ func findConfigurationConflicts(config map[string]interface{}, flags *flag.FlagS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Discard keys that might have a given name, like `labels`.
|
// 2. Discard values that implement NamedOption.
|
||||||
|
// Their configuration name differs from their flag name, like `labels` and `label`.
|
||||||
unknownNamedConflicts := func(f *flag.Flag) {
|
unknownNamedConflicts := func(f *flag.Flag) {
|
||||||
if namedOption, ok := f.Value.(opts.NamedOption); ok {
|
if namedOption, ok := f.Value.(opts.NamedOption); ok {
|
||||||
if _, valid := unknownKeys[namedOption.Name()]; valid {
|
if _, valid := unknownKeys[namedOption.Name()]; valid {
|
||||||
|
|
|
@ -204,9 +204,9 @@ func (cli *DaemonCli) CmdDaemon(args ...string) error {
|
||||||
defaultHost := opts.DefaultHost
|
defaultHost := opts.DefaultHost
|
||||||
if cli.Config.TLS {
|
if cli.Config.TLS {
|
||||||
tlsOptions := tlsconfig.Options{
|
tlsOptions := tlsconfig.Options{
|
||||||
CAFile: cli.Config.TLSOptions.CAFile,
|
CAFile: cli.Config.CommonTLSOptions.CAFile,
|
||||||
CertFile: cli.Config.TLSOptions.CertFile,
|
CertFile: cli.Config.CommonTLSOptions.CertFile,
|
||||||
KeyFile: cli.Config.TLSOptions.KeyFile,
|
KeyFile: cli.Config.CommonTLSOptions.KeyFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
if cli.Config.TLSVerify {
|
if cli.Config.TLSVerify {
|
||||||
|
@ -338,12 +338,12 @@ func loadDaemonCliConfig(config *daemon.Config, daemonFlags *flag.FlagSet, commo
|
||||||
config.LogLevel = commonConfig.LogLevel
|
config.LogLevel = commonConfig.LogLevel
|
||||||
config.TLS = commonConfig.TLS
|
config.TLS = commonConfig.TLS
|
||||||
config.TLSVerify = commonConfig.TLSVerify
|
config.TLSVerify = commonConfig.TLSVerify
|
||||||
config.TLSOptions = daemon.CommonTLSOptions{}
|
config.CommonTLSOptions = daemon.CommonTLSOptions{}
|
||||||
|
|
||||||
if commonConfig.TLSOptions != nil {
|
if commonConfig.TLSOptions != nil {
|
||||||
config.TLSOptions.CAFile = commonConfig.TLSOptions.CAFile
|
config.CommonTLSOptions.CAFile = commonConfig.TLSOptions.CAFile
|
||||||
config.TLSOptions.CertFile = commonConfig.TLSOptions.CertFile
|
config.CommonTLSOptions.CertFile = commonConfig.TLSOptions.CertFile
|
||||||
config.TLSOptions.KeyFile = commonConfig.TLSOptions.KeyFile
|
config.CommonTLSOptions.KeyFile = commonConfig.TLSOptions.KeyFile
|
||||||
}
|
}
|
||||||
|
|
||||||
if configFile != "" {
|
if configFile != "" {
|
||||||
|
|
|
@ -51,8 +51,8 @@ func TestLoadDaemonCliConfigWithTLS(t *testing.T) {
|
||||||
if loadedConfig == nil {
|
if loadedConfig == nil {
|
||||||
t.Fatalf("expected configuration %v, got nil", c)
|
t.Fatalf("expected configuration %v, got nil", c)
|
||||||
}
|
}
|
||||||
if loadedConfig.TLSOptions.CAFile != "/tmp/ca.pem" {
|
if loadedConfig.CommonTLSOptions.CAFile != "/tmp/ca.pem" {
|
||||||
t.Fatalf("expected /tmp/ca.pem, got %s: %q", loadedConfig.TLSOptions.CAFile, loadedConfig)
|
t.Fatalf("expected /tmp/ca.pem, got %s: %q", loadedConfig.CommonTLSOptions.CAFile, loadedConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,9 +217,12 @@ func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadDaemonCliConfigWithTLSOptions(t *testing.T) {
|
func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) {
|
||||||
c := &daemon.Config{}
|
c := &daemon.Config{}
|
||||||
common := &cli.CommonFlags{}
|
common := &cli.CommonFlags{}
|
||||||
|
flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
|
||||||
|
flags.String([]string{"-tlscacert"}, "", "")
|
||||||
|
flags.String([]string{"-log-driver"}, "", "")
|
||||||
|
|
||||||
f, err := ioutil.TempFile("", "docker-config-")
|
f, err := ioutil.TempFile("", "docker-config-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -227,11 +230,9 @@ func TestLoadDaemonCliConfigWithTLSOptions(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
configFile := f.Name()
|
configFile := f.Name()
|
||||||
f.Write([]byte(`{"tls-opts": {"tlscacert": "/etc/certs/ca.pem"}}`))
|
f.Write([]byte(`{"tlscacert": "/etc/certs/ca.pem", "log-driver": "syslog"}`))
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
|
|
||||||
flags.String([]string{"-tlscacert"}, "", "")
|
|
||||||
loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
|
loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -239,7 +240,10 @@ func TestLoadDaemonCliConfigWithTLSOptions(t *testing.T) {
|
||||||
if loadedConfig == nil {
|
if loadedConfig == nil {
|
||||||
t.Fatalf("expected configuration %v, got nil", c)
|
t.Fatalf("expected configuration %v, got nil", c)
|
||||||
}
|
}
|
||||||
if loadedConfig.TLSOptions.CAFile != "/etc/certs/ca.pem" {
|
if loadedConfig.CommonTLSOptions.CAFile != "/etc/certs/ca.pem" {
|
||||||
t.Fatalf("expected CA file path /etc/certs/ca.pem, got %v", loadedConfig.TLSOptions.CAFile)
|
t.Fatalf("expected CA file path /etc/certs/ca.pem, got %v", loadedConfig.CommonTLSOptions.CAFile)
|
||||||
|
}
|
||||||
|
if loadedConfig.LogConfig.Type != "syslog" {
|
||||||
|
t.Fatalf("expected LogConfig type syslog, got %v", loadedConfig.LogConfig.Type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -838,10 +838,8 @@ This is a full example of the allowed configuration options in the file:
|
||||||
"storage-driver": "",
|
"storage-driver": "",
|
||||||
"storage-opts": "",
|
"storage-opts": "",
|
||||||
"labels": [],
|
"labels": [],
|
||||||
"log-config": {
|
|
||||||
"log-driver": "",
|
"log-driver": "",
|
||||||
"log-opts": []
|
"log-opts": [],
|
||||||
},
|
|
||||||
"mtu": 0,
|
"mtu": 0,
|
||||||
"pidfile": "",
|
"pidfile": "",
|
||||||
"graph": "",
|
"graph": "",
|
||||||
|
@ -853,11 +851,9 @@ This is a full example of the allowed configuration options in the file:
|
||||||
"log-level": "",
|
"log-level": "",
|
||||||
"tls": true,
|
"tls": true,
|
||||||
"tlsverify": true,
|
"tlsverify": true,
|
||||||
"tls-opts": {
|
|
||||||
"tlscacert": "",
|
"tlscacert": "",
|
||||||
"tlscert": "",
|
"tlscert": "",
|
||||||
"tlskey": ""
|
"tlskey": "",
|
||||||
},
|
|
||||||
"api-cors-headers": "",
|
"api-cors-headers": "",
|
||||||
"selinux-enabled": false,
|
"selinux-enabled": false,
|
||||||
"userns-remap": "",
|
"userns-remap": "",
|
||||||
|
|
Loading…
Reference in a new issue