2019-01-15 13:28:04 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2019-08-03 01:58:23 +00:00
|
|
|
"github.com/containous/traefik/v2/pkg/config/dynamic"
|
|
|
|
"github.com/containous/traefik/v2/pkg/log"
|
|
|
|
"github.com/containous/traefik/v2/pkg/server/internal"
|
|
|
|
"github.com/containous/traefik/v2/pkg/tls"
|
2019-01-15 13:28:04 +00:00
|
|
|
)
|
|
|
|
|
2019-07-10 07:26:04 +00:00
|
|
|
func mergeConfiguration(configurations dynamic.Configurations) dynamic.Configuration {
|
|
|
|
conf := dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: make(map[string]*dynamic.Router),
|
|
|
|
Middlewares: make(map[string]*dynamic.Middleware),
|
|
|
|
Services: make(map[string]*dynamic.Service),
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
TCP: &dynamic.TCPConfiguration{
|
|
|
|
Routers: make(map[string]*dynamic.TCPRouter),
|
|
|
|
Services: make(map[string]*dynamic.TCPService),
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
TLS: &dynamic.TLSConfiguration{
|
2019-06-27 21:58:03 +00:00
|
|
|
Stores: make(map[string]tls.Store),
|
|
|
|
Options: make(map[string]tls.Options),
|
|
|
|
},
|
2019-01-15 13:28:04 +00:00
|
|
|
}
|
|
|
|
|
2019-06-21 15:18:05 +00:00
|
|
|
var defaultTLSOptionProviders []string
|
2019-01-15 13:28:04 +00:00
|
|
|
for provider, configuration := range configurations {
|
2019-03-14 08:30:04 +00:00
|
|
|
if configuration.HTTP != nil {
|
|
|
|
for routerName, router := range configuration.HTTP.Routers {
|
|
|
|
conf.HTTP.Routers[internal.MakeQualifiedName(provider, routerName)] = router
|
|
|
|
}
|
|
|
|
for middlewareName, middleware := range configuration.HTTP.Middlewares {
|
|
|
|
conf.HTTP.Middlewares[internal.MakeQualifiedName(provider, middlewareName)] = middleware
|
|
|
|
}
|
|
|
|
for serviceName, service := range configuration.HTTP.Services {
|
|
|
|
conf.HTTP.Services[internal.MakeQualifiedName(provider, serviceName)] = service
|
|
|
|
}
|
2019-01-15 13:28:04 +00:00
|
|
|
}
|
2019-03-14 08:30:04 +00:00
|
|
|
|
|
|
|
if configuration.TCP != nil {
|
|
|
|
for routerName, router := range configuration.TCP.Routers {
|
|
|
|
conf.TCP.Routers[internal.MakeQualifiedName(provider, routerName)] = router
|
|
|
|
}
|
|
|
|
for serviceName, service := range configuration.TCP.Services {
|
|
|
|
conf.TCP.Services[internal.MakeQualifiedName(provider, serviceName)] = service
|
|
|
|
}
|
2019-01-15 13:28:04 +00:00
|
|
|
}
|
2019-03-14 08:30:04 +00:00
|
|
|
|
2019-06-27 21:58:03 +00:00
|
|
|
if configuration.TLS != nil {
|
|
|
|
conf.TLS.Certificates = append(conf.TLS.Certificates, configuration.TLS.Certificates...)
|
2019-03-14 08:30:04 +00:00
|
|
|
|
2019-06-27 21:58:03 +00:00
|
|
|
for key, store := range configuration.TLS.Stores {
|
|
|
|
conf.TLS.Stores[key] = store
|
2019-06-21 15:18:05 +00:00
|
|
|
}
|
|
|
|
|
2019-06-27 21:58:03 +00:00
|
|
|
for tlsOptionsName, options := range configuration.TLS.Options {
|
|
|
|
if tlsOptionsName != "default" {
|
|
|
|
tlsOptionsName = internal.MakeQualifiedName(provider, tlsOptionsName)
|
|
|
|
} else {
|
|
|
|
defaultTLSOptionProviders = append(defaultTLSOptionProviders, provider)
|
|
|
|
}
|
|
|
|
|
|
|
|
conf.TLS.Options[tlsOptionsName] = options
|
|
|
|
}
|
2019-03-14 08:30:04 +00:00
|
|
|
}
|
2019-01-15 13:28:04 +00:00
|
|
|
}
|
|
|
|
|
2019-06-21 15:18:05 +00:00
|
|
|
if len(defaultTLSOptionProviders) == 0 {
|
2019-06-27 21:58:03 +00:00
|
|
|
conf.TLS.Options["default"] = tls.Options{}
|
2019-06-21 15:18:05 +00:00
|
|
|
} else if len(defaultTLSOptionProviders) > 1 {
|
|
|
|
log.WithoutContext().Errorf("Default TLS Options defined multiple times in %v", defaultTLSOptionProviders)
|
|
|
|
// We do not set an empty tls.TLS{} as above so that we actually get a "cascading failure" later on,
|
|
|
|
// i.e. routers depending on this missing TLS option will fail to initialize as well.
|
2019-06-27 21:58:03 +00:00
|
|
|
delete(conf.TLS.Options, "default")
|
2019-06-21 15:18:05 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 13:28:04 +00:00
|
|
|
return conf
|
|
|
|
}
|