diff --git a/provider/file/file.go b/provider/file/file.go index b15236768..ff4d7055e 100644 --- a/provider/file/file.go +++ b/provider/file/file.go @@ -175,17 +175,36 @@ func (p *Provider) loadFileConfig(filename string, parseTemplate bool) (*types.C } else { configuration, err = p.DecodeConfiguration(fileContent) } - if err != nil { return nil, err } + + var tlsConfigs []*tls.Configuration + for _, conf := range configuration.TLS { + bytes, err := conf.Certificate.CertFile.Read() + if err != nil { + log.Error(err) + continue + } + conf.Certificate.CertFile = tls.FileOrContent(string(bytes)) + + bytes, err = conf.Certificate.KeyFile.Read() + if err != nil { + log.Error(err) + continue + } + conf.Certificate.KeyFile = tls.FileOrContent(string(bytes)) + tlsConfigs = append(tlsConfigs, conf) + } + configuration.TLS = tlsConfigs + if configuration == nil || configuration.Backends == nil && configuration.Frontends == nil && configuration.TLS == nil { configuration = &types.Configuration{ Frontends: make(map[string]*types.Frontend), Backends: make(map[string]*types.Backend), } } - return configuration, err + return configuration, nil } func (p *Provider) loadFileConfigFromDirectory(directory string, configuration *types.Configuration) (*types.Configuration, error) { diff --git a/provider/file/file_test.go b/provider/file/file_test.go index eae4f847f..38321d764 100644 --- a/provider/file/file_test.go +++ b/provider/file/file_test.go @@ -12,6 +12,7 @@ import ( "github.com/containous/traefik/safe" "github.com/containous/traefik/types" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) // createRandomFile Helper @@ -332,3 +333,24 @@ func createProvider(t *testing.T, test ProvideTestCase, watch bool) (*Provider, os.Remove(tempDir) } } + +func TestTLSContent(t *testing.T) { + tempDir := createTempDir(t, "testdir") + defer os.Remove(tempDir) + + fileTLS := createRandomFile(t, tempDir, "CONTENT") + fileConfig := createRandomFile(t, tempDir, ` +[[tls]] +entryPoints = ["https"] + [tls.certificate] + certFile = "`+fileTLS.Name()+`" + keyFile = "`+fileTLS.Name()+`" +`) + + provider := &Provider{} + configuration, err := provider.loadFileConfig(fileConfig.Name(), true) + require.NoError(t, err) + + require.Equal(t, "CONTENT", configuration.TLS[0].Certificate.CertFile.String()) + require.Equal(t, "CONTENT", configuration.TLS[0].Certificate.KeyFile.String()) +}