Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #929 from zcc35357949/mirror_dfgetconfig
Browse files Browse the repository at this point in the history
bugfix: paas registry mirror tls config into dfget config.
  • Loading branch information
starnop authored Sep 24, 2019
2 parents a90f276 + d037f31 commit 6d3a6d5
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dfdaemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
59 changes: 59 additions & 0 deletions dfdaemon/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }()
Expand Down

0 comments on commit 6d3a6d5

Please sign in to comment.