diff --git a/integration/rest_test.go b/integration/rest_test.go index 1cb330cf2..a5da9df05 100644 --- a/integration/rest_test.go +++ b/integration/rest_test.go @@ -32,41 +32,81 @@ func (s *RestSuite) TestSimpleConfiguration(c *check.C) { err = try.GetRequest("http://127.0.0.1:8000/", 1000*time.Millisecond, try.StatusCodeIs(http.StatusNotFound)) c.Assert(err, checker.IsNil) - config := dynamic.HTTPConfiguration{ - Routers: map[string]*dynamic.Router{ - "router1": { - EntryPoints: []string{"web"}, - Middlewares: []string{}, - Service: "service1", - Rule: "PathPrefix(`/`)", - }, - }, - Services: map[string]*dynamic.Service{ - "service1": { - LoadBalancer: &dynamic.LoadBalancerService{ - Servers: []dynamic.Server{ - { - URL: "http://" + s.composeProject.Container(c, "whoami1").NetworkSettings.IPAddress + ":80", + testCase := []struct { + desc string + config *dynamic.Configuration + ruleMatch string + }{ + { + desc: "deploy http configuration", + config: &dynamic.Configuration{ + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ + "router1": { + EntryPoints: []string{"web"}, + Middlewares: []string{}, + Service: "service1", + Rule: "PathPrefix(`/`)", + }, + }, + Services: map[string]*dynamic.Service{ + "service1": { + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ + { + URL: "http://" + s.composeProject.Container(c, "whoami1").NetworkSettings.IPAddress + ":80", + }, + }, + }, }, }, }, }, + ruleMatch: "PathPrefix(`/`)", + }, + { + desc: "deploy tcp configuration", + config: &dynamic.Configuration{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ + "router1": { + EntryPoints: []string{"web"}, + Service: "service1", + Rule: "HostSNI(`*`)", + }, + }, + Services: map[string]*dynamic.TCPService{ + "service1": { + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ + { + Address: s.composeProject.Container(c, "whoami1").NetworkSettings.IPAddress + ":80", + }, + }, + }, + }, + }, + }, + }, + ruleMatch: "HostSNI(`*`)", }, } - json, err := json.Marshal(config) - c.Assert(err, checker.IsNil) + for _, test := range testCase { + json, err := json.Marshal(test.config) + c.Assert(err, checker.IsNil) - request, err := http.NewRequest(http.MethodPut, "http://127.0.0.1:8080/api/providers/rest", bytes.NewReader(json)) - c.Assert(err, checker.IsNil) + request, err := http.NewRequest(http.MethodPut, "http://127.0.0.1:8080/api/providers/rest", bytes.NewReader(json)) + c.Assert(err, checker.IsNil) - response, err := http.DefaultClient.Do(request) - c.Assert(err, checker.IsNil) - c.Assert(response.StatusCode, checker.Equals, http.StatusOK) + response, err := http.DefaultClient.Do(request) + c.Assert(err, checker.IsNil) + c.Assert(response.StatusCode, checker.Equals, http.StatusOK) - err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 1000*time.Millisecond, try.BodyContains("PathPrefix(`/`)")) - c.Assert(err, checker.IsNil) + err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 1000*time.Millisecond, try.BodyContains(test.ruleMatch)) + c.Assert(err, checker.IsNil) - err = try.GetRequest("http://127.0.0.1:8000/", 1000*time.Millisecond, try.StatusCodeIs(http.StatusOK)) - c.Assert(err, checker.IsNil) + err = try.GetRequest("http://127.0.0.1:8000/", 1000*time.Millisecond, try.StatusCodeIs(http.StatusOK)) + c.Assert(err, checker.IsNil) + } } diff --git a/integration/simple_test.go b/integration/simple_test.go index a6c8a3ea5..2b09080bd 100644 --- a/integration/simple_test.go +++ b/integration/simple_test.go @@ -440,13 +440,15 @@ func (s *SimpleSuite) TestMultiprovider(c *check.C) { err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 1000*time.Millisecond, try.BodyContains("service")) c.Assert(err, checker.IsNil) - config := dynamic.HTTPConfiguration{ - Routers: map[string]*dynamic.Router{ - "router1": { - EntryPoints: []string{"web"}, - Middlewares: []string{"customheader@file"}, - Service: "service@file", - Rule: "PathPrefix(`/`)", + config := dynamic.Configuration{ + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ + "router1": { + EntryPoints: []string{"web"}, + Middlewares: []string{"customheader@file"}, + Service: "service@file", + Rule: "PathPrefix(`/`)", + }, }, }, } diff --git a/pkg/config/dynamic/config.go b/pkg/config/dynamic/config.go index 07845ca97..225cd12f1 100644 --- a/pkg/config/dynamic/config.go +++ b/pkg/config/dynamic/config.go @@ -30,7 +30,7 @@ type Configuration struct { // TLSConfiguration contains all the configuration parameters of a TLS connection. type TLSConfiguration struct { - Certificates []*tls.CertAndStores `json:"-" toml:"certificates,omitempty" yaml:"certificates,omitempty" label:"-"` + Certificates []*tls.CertAndStores `json:"certificates,omitempty" toml:"certificates,omitempty" yaml:"certificates,omitempty" label:"-"` Options map[string]tls.Options `json:"options,omitempty" toml:"options,omitempty" yaml:"options,omitempty"` Stores map[string]tls.Store `json:"stores,omitempty" toml:"stores,omitempty" yaml:"stores,omitempty"` } diff --git a/pkg/provider/rest/rest.go b/pkg/provider/rest/rest.go index 45cf025bf..8e3028286 100644 --- a/pkg/provider/rest/rest.go +++ b/pkg/provider/rest/rest.go @@ -48,7 +48,7 @@ func (p *Provider) Append(systemRouter *mux.Router) { return } - configuration := new(dynamic.HTTPConfiguration) + configuration := new(dynamic.Configuration) body, _ := ioutil.ReadAll(request.Body) if err := json.Unmarshal(body, configuration); err != nil { @@ -57,9 +57,7 @@ func (p *Provider) Append(systemRouter *mux.Router) { return } - p.configurationChan <- dynamic.Message{ProviderName: "rest", Configuration: &dynamic.Configuration{ - HTTP: configuration, - }} + p.configurationChan <- dynamic.Message{ProviderName: "rest", Configuration: configuration} if err := templatesRenderer.JSON(response, http.StatusOK, configuration); err != nil { log.WithoutContext().Error(err) } diff --git a/pkg/server/server_configuration.go b/pkg/server/server_configuration.go index c0aa203ac..1a184274e 100644 --- a/pkg/server/server_configuration.go +++ b/pkg/server/server_configuration.go @@ -175,8 +175,22 @@ func (s *Server) preLoadConfiguration(configMsg dynamic.Message) { logger := log.WithoutContext().WithField(log.ProviderName, configMsg.ProviderName) if log.GetLevel() == logrus.DebugLevel { - jsonConf, _ := json.Marshal(configMsg.Configuration) - logger.Debugf("Configuration received from provider %s: %s", configMsg.ProviderName, string(jsonConf)) + copyConf := configMsg.Configuration.DeepCopy() + if copyConf.TLS != nil { + copyConf.TLS.Certificates = nil + + for _, v := range copyConf.TLS.Stores { + v.DefaultCertificate = nil + } + } + + jsonConf, err := json.Marshal(copyConf) + if err != nil { + logger.Errorf("Could not marshal dynamic configuration: %v", err) + logger.Debugf("Configuration received from provider %s: [struct] %#v", configMsg.ProviderName, copyConf) + } else { + logger.Debugf("Configuration received from provider %s: %s", configMsg.ProviderName, string(jsonConf)) + } } if isEmptyConfiguration(configMsg.Configuration) {