From f93c68baf48ec57216aa9b630a1e40e03d2ed348 Mon Sep 17 00:00:00 2001 From: zhouchencheng Date: Wed, 18 Sep 2019 16:15:36 +0800 Subject: [PATCH] bugfix: paas registry mirror tls config into dfget config. Signed-off-by: zhouchencheng --- dfdaemon/config/config.go | 10 ++++++ dfdaemon/config/config_test.go | 59 ++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/dfdaemon/config/config.go b/dfdaemon/config/config.go index 116f22144..f986f292b 100644 --- a/dfdaemon/config/config.go +++ b/dfdaemon/config/config.go @@ -151,6 +151,16 @@ func (p *Properties) DFGetConfig() DFGetConfig { if p.HijackHTTPS != nil { dfgetConfig.HostsConfig = p.HijackHTTPS.Hosts } + if p.RegistryMirror != nil { + exp, err := NewRegexp(p.RegistryMirror.Remote.Host) + if err == nil { + dfgetConfig.HostsConfig = append(dfgetConfig.HostsConfig, &HijackHost{ + Regx: exp, + Insecure: p.RegistryMirror.Insecure, + Certs: p.RegistryMirror.Certs, + }) + } + } return dfgetConfig } diff --git a/dfdaemon/config/config_test.go b/dfdaemon/config/config_test.go index 0aa89e8a0..3fca234df 100644 --- a/dfdaemon/config/config_test.go +++ b/dfdaemon/config/config_test.go @@ -269,6 +269,65 @@ func (ts *configTestSuite) TestMirrorTLSConfig() { r.Equal(m.Insecure, m.TLSConfig().InsecureSkipVerify) } +func (ts *configTestSuite) TestDFGetConfig() { + c := defaultConfig() + r := ts.Require() + + { + flagsConfigs := c.DFGetConfig() + r.Contains(flagsConfigs.DfgetFlags, "--dfdaemon") + r.Equal(c.SuperNodes, flagsConfigs.SuperNodes) + r.Equal(c.RateLimit.String(), flagsConfigs.RateLimit) + r.Equal(c.DFRepo, flagsConfigs.DFRepo) + r.Equal(c.DFPath, flagsConfigs.DFPath) + + c.Verbose = true + flagsConfigs = c.DFGetConfig() + r.Contains(flagsConfigs.DfgetFlags, "--verbose") + } + + { + aRegex, err := NewRegexp("a.registry.com") + r.Nil(err) + bRegex, err := NewRegexp("b.registry.com") + r.Nil(err) + c.HijackHTTPS = &HijackConfig{ + Hosts: []*HijackHost{ + { + Regx: aRegex, + Insecure: true, + Certs: nil, + }, + { + Regx: bRegex, + Insecure: false, + Certs: &CertPool{ + CertPool: x509.NewCertPool(), + }, + }, + }, + } + r.Equal(c.HijackHTTPS.Hosts, c.DFGetConfig().HostsConfig) + } + + { + url, err := NewURL("c.registry.com") + r.Nil(err) + c.RegistryMirror = &RegistryMirror{ + Remote: url, + Certs: &CertPool{ + CertPool: x509.NewCertPool(), + }, + Insecure: false, + } + mirrorConfigs := c.DFGetConfig() + r.Equal(len(mirrorConfigs.HostsConfig), 3) + r.Equal(mirrorConfigs.HostsConfig[len(mirrorConfigs.HostsConfig)-1].Regx.String(), c.RegistryMirror.Remote.Host) + r.Equal(mirrorConfigs.HostsConfig[len(mirrorConfigs.HostsConfig)-1].Certs, c.RegistryMirror.Certs) + r.Equal(mirrorConfigs.HostsConfig[len(mirrorConfigs.HostsConfig)-1].Insecure, c.RegistryMirror.Insecure) + } +} + func (ts *configTestSuite) TestSerialization() { currentFs := fs defer func() { fs = currentFs }()