From 9a7821b8fac6cb9e130774a99721648d93f26c84 Mon Sep 17 00:00:00 2001 From: NicoMen Date: Thu, 21 Dec 2017 21:24:03 +0100 Subject: [PATCH] Send empty configuration from file provider --- integration/https_test.go | 41 +++++++++++++++++++++------------------ provider/file/file.go | 10 ++++++---- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/integration/https_test.go b/integration/https_test.go index ab576b973..2582dfcda 100644 --- a/integration/https_test.go +++ b/integration/https_test.go @@ -590,7 +590,7 @@ func (s *HTTPSSuite) TestWithSNIDynamicConfigRouteWithTlsConfigurationDeletion(c c.Assert(err, checker.IsNil) c.Assert(resp.StatusCode, checker.Equals, http.StatusResetContent) // Change certificates configuration file content - modifyCertificateConfFileContent(c, "snitest.com", dynamicConfFileName, "https02") + modifyCertificateConfFileContent(c, "", dynamicConfFileName, "https02") err = try.Do(60*time.Second, func() error { resp, err = client.Do(req) @@ -615,28 +615,31 @@ func (s *HTTPSSuite) TestWithSNIDynamicConfigRouteWithTlsConfigurationDeletion(c // modifyCertificateConfFileContent replaces the content of a HTTPS configuration file. func modifyCertificateConfFileContent(c *check.C, certFileName, confFileName, entryPoint string) { - tlsConf := types.Configuration{ - TLSConfiguration: []*traefikTls.Configuration{ - { - Certificate: &traefikTls.Certificate{ - CertFile: traefikTls.FileOrContent("fixtures/https/" + certFileName + ".cert"), - KeyFile: traefikTls.FileOrContent("fixtures/https/" + certFileName + ".key"), - }, - EntryPoints: []string{entryPoint}, - }, - }, - } - var confBuffer bytes.Buffer - e := toml.NewEncoder(&confBuffer) - err := e.Encode(tlsConf) - c.Assert(err, checker.IsNil) - f, err := os.OpenFile("./"+confFileName, os.O_WRONLY, os.ModeExclusive) c.Assert(err, checker.IsNil) defer func() { f.Close() }() f.Truncate(0) - _, err = f.Write(confBuffer.Bytes()) - c.Assert(err, checker.IsNil) + // If certificate file is not provided, just truncate the configuration file + if len(certFileName) > 0 { + tlsConf := types.Configuration{ + TLSConfiguration: []*traefikTls.Configuration{ + { + Certificate: &traefikTls.Certificate{ + CertFile: traefikTls.FileOrContent("fixtures/https/" + certFileName + ".cert"), + KeyFile: traefikTls.FileOrContent("fixtures/https/" + certFileName + ".key"), + }, + EntryPoints: []string{entryPoint}, + }, + }, + } + var confBuffer bytes.Buffer + e := toml.NewEncoder(&confBuffer) + err := e.Encode(tlsConf) + c.Assert(err, checker.IsNil) + + _, err = f.Write(confBuffer.Bytes()) + c.Assert(err, checker.IsNil) + } } diff --git a/provider/file/file.go b/provider/file/file.go index 918c7cf4d..06e25bb2c 100644 --- a/provider/file/file.go +++ b/provider/file/file.go @@ -126,7 +126,10 @@ func sendConfigToChannel(configurationChan chan<- types.ConfigMessage, configura } func loadFileConfig(filename string) (*types.Configuration, error) { - configuration := new(types.Configuration) + configuration := &types.Configuration{ + Frontends: make(map[string]*types.Frontend), + Backends: make(map[string]*types.Backend), + } if _, err := toml.DecodeFile(filename, configuration); err != nil { return nil, fmt.Errorf("error reading configuration file: %s", err) } @@ -142,9 +145,8 @@ func loadFileConfigFromDirectory(directory string, configuration *types.Configur if configuration == nil { configuration = &types.Configuration{ - Frontends: make(map[string]*types.Frontend), - Backends: make(map[string]*types.Backend), - TLSConfiguration: make([]*tls.Configuration, 0), + Frontends: make(map[string]*types.Frontend), + Backends: make(map[string]*types.Backend), } }