mirror of
https://github.com/traefik/traefik.git
synced 2025-08-18 04:27:08 +02:00
Check for dynamic tls updates on configuration preload
This commit is contained in:
parent
32f5e0df8f
commit
40bb0cd879
@ -175,17 +175,36 @@ func (p *Provider) loadFileConfig(filename string, parseTemplate bool) (*types.C
|
|||||||
} else {
|
} else {
|
||||||
configuration, err = p.DecodeConfiguration(fileContent)
|
configuration, err = p.DecodeConfiguration(fileContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if configuration == nil || configuration.Backends == nil && configuration.Frontends == nil && configuration.TLS == nil {
|
||||||
configuration = &types.Configuration{
|
configuration = &types.Configuration{
|
||||||
Frontends: make(map[string]*types.Frontend),
|
Frontends: make(map[string]*types.Frontend),
|
||||||
Backends: make(map[string]*types.Backend),
|
Backends: make(map[string]*types.Backend),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return configuration, err
|
return configuration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) loadFileConfigFromDirectory(directory string, configuration *types.Configuration) (*types.Configuration, error) {
|
func (p *Provider) loadFileConfigFromDirectory(directory string, configuration *types.Configuration) (*types.Configuration, error) {
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/containous/traefik/safe"
|
"github.com/containous/traefik/safe"
|
||||||
"github.com/containous/traefik/types"
|
"github.com/containous/traefik/types"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// createRandomFile Helper
|
// createRandomFile Helper
|
||||||
@ -332,3 +333,24 @@ func createProvider(t *testing.T, test ProvideTestCase, watch bool) (*Provider,
|
|||||||
os.Remove(tempDir)
|
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())
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user