From 1ea98d3d31d8f2433c4bcd9a6b5685b5c051418a Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Feb 2024 10:26:07 +0100 Subject: [PATCH 01/19] Fix codename --- CHANGELOG.md | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 460b5806f..a01c320c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ - **[webui]** Fixes the Header Button ([#10395](https://github.com/traefik/traefik/pull/10395) by [mdeliatf](https://github.com/mdeliatf)) - **[webui]** Fix URL encode resource's id before calling API endpoints ([#10292](https://github.com/traefik/traefik/pull/10292) by [andsarr](https://github.com/andsarr)) - **Documentation:** +**Documentation:** - **[acme]** Fix TLS challenge explanation ([#10293](https://github.com/traefik/traefik/pull/10293) by [cavokz](https://github.com/cavokz)) - **[docker]** Update wording of compose example ([#10276](https://github.com/traefik/traefik/pull/10276) by [svx](https://github.com/svx)) - **[docker,acme]** Fix typo ([#10294](https://github.com/traefik/traefik/pull/10294) by [youpsla](https://github.com/youpsla)) diff --git a/Makefile b/Makefile index 94b8a831c..7a810fff8 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ GIT_BRANCH := $(subst heads/,,$(shell git rev-parse --abbrev-ref HEAD 2>/dev/nul REPONAME := $(shell echo $(REPO) | tr '[:upper:]' '[:lower:]') BIN_NAME := traefik -CODENAME := cheddar +CODENAME ?= cheddar DATE := $(shell date -u '+%Y-%m-%d_%I:%M:%S%p') From 6a2db4e4e958e5301cabe2d68bb8c5fc0f5c2d7d Mon Sep 17 00:00:00 2001 From: xpac1985 Date: Thu, 15 Feb 2024 15:20:04 +0100 Subject: [PATCH 02/19] Fix typo in statsd metrics docs --- docs/content/observability/metrics/statsd.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/observability/metrics/statsd.md b/docs/content/observability/metrics/statsd.md index 79472dd06..042e937cd 100644 --- a/docs/content/observability/metrics/statsd.md +++ b/docs/content/observability/metrics/statsd.md @@ -69,7 +69,7 @@ metrics: _Optional, Default=false_ -Enable metrics on entry points. +Enable metrics on routers. ```yaml tab="File (YAML)" metrics: From 1e7dbc70a0a28f4ad7bed92d845faecdf2cb97d9 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Thu, 15 Feb 2024 16:40:05 +0100 Subject: [PATCH 03/19] fix: don't allow routers higher than internal ones --- .../reference/static-configuration/cli-ref.md | 2 +- .../reference/static-configuration/env-ref.md | 2 +- docs/content/routing/entrypoints.md | 2 +- integration/testdata/rawdata-consul.json | 4 ++-- integration/testdata/rawdata-etcd.json | 4 ++-- integration/testdata/rawdata-gateway.json | 4 ++-- .../testdata/rawdata-ingress-label-selector.json | 4 ++-- integration/testdata/rawdata-ingress.json | 4 ++-- integration/testdata/rawdata-ingressclass.json | 4 ++-- integration/testdata/rawdata-redis.json | 4 ++-- integration/testdata/rawdata-zk.json | 4 ++-- pkg/config/static/entrypoints.go | 2 +- .../fixtures/api_insecure_with_dashboard.json | 6 +++--- .../fixtures/api_insecure_without_dashboard.json | 4 ++-- .../traefik/fixtures/full_configuration.json | 14 +++++++------- pkg/provider/traefik/fixtures/ping_simple.json | 4 ++-- .../traefik/fixtures/prometheus_simple.json | 4 ++-- pkg/provider/traefik/fixtures/rest_insecure.json | 4 ++-- pkg/provider/traefik/internal.go | 14 +++++++------- 19 files changed, 45 insertions(+), 45 deletions(-) diff --git a/docs/content/reference/static-configuration/cli-ref.md b/docs/content/reference/static-configuration/cli-ref.md index f67a3b3c1..60a8c6513 100644 --- a/docs/content/reference/static-configuration/cli-ref.md +++ b/docs/content/reference/static-configuration/cli-ref.md @@ -127,7 +127,7 @@ Default middlewares for the routers linked to the entry point. Applies a permanent redirection. (Default: ```true```) `--entrypoints..http.redirections.entrypoint.priority`: -Priority of the generated router. (Default: ```2147483646```) +Priority of the generated router. (Default: ```9223372036854775806```) `--entrypoints..http.redirections.entrypoint.scheme`: Scheme used for the redirection. (Default: ```https```) diff --git a/docs/content/reference/static-configuration/env-ref.md b/docs/content/reference/static-configuration/env-ref.md index 41eb2697f..849601f63 100644 --- a/docs/content/reference/static-configuration/env-ref.md +++ b/docs/content/reference/static-configuration/env-ref.md @@ -136,7 +136,7 @@ Default middlewares for the routers linked to the entry point. Applies a permanent redirection. (Default: ```true```) `TRAEFIK_ENTRYPOINTS__HTTP_REDIRECTIONS_ENTRYPOINT_PRIORITY`: -Priority of the generated router. (Default: ```2147483646```) +Priority of the generated router. (Default: ```9223372036854775806```) `TRAEFIK_ENTRYPOINTS__HTTP_REDIRECTIONS_ENTRYPOINT_SCHEME`: Scheme used for the redirection. (Default: ```https```) diff --git a/docs/content/routing/entrypoints.md b/docs/content/routing/entrypoints.md index fe78191e0..afe2c05f9 100644 --- a/docs/content/routing/entrypoints.md +++ b/docs/content/routing/entrypoints.md @@ -865,7 +865,7 @@ This section is a convenience to enable (permanent) redirecting of all incoming ??? info "`entryPoint.priority`" - _Optional, Default=MaxInt32-1 (2147483646)_ + _Optional, Default=MaxInt-1_ Priority of the generated router. diff --git a/integration/testdata/rawdata-consul.json b/integration/testdata/rawdata-consul.json index 0bf110eac..74a22e7bc 100644 --- a/integration/testdata/rawdata-consul.json +++ b/integration/testdata/rawdata-consul.json @@ -53,7 +53,7 @@ ], "service": "api@internal", "rule": "PathPrefix(`/api`)", - "priority": 2147483646, + "priority": 9223372036854775806, "status": "enabled", "using": [ "traefik" @@ -69,7 +69,7 @@ ], "service": "dashboard@internal", "rule": "PathPrefix(`/`)", - "priority": 2147483645, + "priority": 9223372036854775805, "status": "enabled", "using": [ "traefik" diff --git a/integration/testdata/rawdata-etcd.json b/integration/testdata/rawdata-etcd.json index 92b4aa2b5..b1b015ae2 100644 --- a/integration/testdata/rawdata-etcd.json +++ b/integration/testdata/rawdata-etcd.json @@ -53,7 +53,7 @@ ], "service": "api@internal", "rule": "PathPrefix(`/api`)", - "priority": 2147483646, + "priority": 9223372036854775806, "status": "enabled", "using": [ "traefik" @@ -69,7 +69,7 @@ ], "service": "dashboard@internal", "rule": "PathPrefix(`/`)", - "priority": 2147483645, + "priority": 9223372036854775805, "status": "enabled", "using": [ "traefik" diff --git a/integration/testdata/rawdata-gateway.json b/integration/testdata/rawdata-gateway.json index a18a09ef8..f3e754051 100644 --- a/integration/testdata/rawdata-gateway.json +++ b/integration/testdata/rawdata-gateway.json @@ -6,7 +6,7 @@ ], "service": "api@internal", "rule": "PathPrefix(`/api`)", - "priority": 2147483646, + "priority": 9223372036854775806, "status": "enabled", "using": [ "traefik" @@ -22,7 +22,7 @@ ], "service": "dashboard@internal", "rule": "PathPrefix(`/`)", - "priority": 2147483645, + "priority": 9223372036854775805, "status": "enabled", "using": [ "traefik" diff --git a/integration/testdata/rawdata-ingress-label-selector.json b/integration/testdata/rawdata-ingress-label-selector.json index 497835714..101e82925 100644 --- a/integration/testdata/rawdata-ingress-label-selector.json +++ b/integration/testdata/rawdata-ingress-label-selector.json @@ -6,7 +6,7 @@ ], "service": "api@internal", "rule": "PathPrefix(`/api`)", - "priority": 2147483646, + "priority": 9223372036854775806, "status": "enabled", "using": [ "traefik" @@ -22,7 +22,7 @@ ], "service": "dashboard@internal", "rule": "PathPrefix(`/`)", - "priority": 2147483645, + "priority": 9223372036854775805, "status": "enabled", "using": [ "traefik" diff --git a/integration/testdata/rawdata-ingress.json b/integration/testdata/rawdata-ingress.json index 2943e4cbd..564a15e20 100644 --- a/integration/testdata/rawdata-ingress.json +++ b/integration/testdata/rawdata-ingress.json @@ -6,7 +6,7 @@ ], "service": "api@internal", "rule": "PathPrefix(`/api`)", - "priority": 2147483646, + "priority": 9223372036854775806, "status": "enabled", "using": [ "traefik" @@ -22,7 +22,7 @@ ], "service": "dashboard@internal", "rule": "PathPrefix(`/`)", - "priority": 2147483645, + "priority": 9223372036854775805, "status": "enabled", "using": [ "traefik" diff --git a/integration/testdata/rawdata-ingressclass.json b/integration/testdata/rawdata-ingressclass.json index 0944a7cff..952bc95b2 100644 --- a/integration/testdata/rawdata-ingressclass.json +++ b/integration/testdata/rawdata-ingressclass.json @@ -6,7 +6,7 @@ ], "service": "api@internal", "rule": "PathPrefix(`/api`)", - "priority": 2147483646, + "priority": 9223372036854775806, "status": "enabled", "using": [ "traefik" @@ -22,7 +22,7 @@ ], "service": "dashboard@internal", "rule": "PathPrefix(`/`)", - "priority": 2147483645, + "priority": 9223372036854775805, "status": "enabled", "using": [ "traefik" diff --git a/integration/testdata/rawdata-redis.json b/integration/testdata/rawdata-redis.json index 1dda1cebe..16f81ae48 100644 --- a/integration/testdata/rawdata-redis.json +++ b/integration/testdata/rawdata-redis.json @@ -53,7 +53,7 @@ ], "service": "api@internal", "rule": "PathPrefix(`/api`)", - "priority": 2147483646, + "priority": 9223372036854775806, "status": "enabled", "using": [ "traefik" @@ -69,7 +69,7 @@ ], "service": "dashboard@internal", "rule": "PathPrefix(`/`)", - "priority": 2147483645, + "priority": 9223372036854775805, "status": "enabled", "using": [ "traefik" diff --git a/integration/testdata/rawdata-zk.json b/integration/testdata/rawdata-zk.json index 67d5c47f9..138bc168d 100644 --- a/integration/testdata/rawdata-zk.json +++ b/integration/testdata/rawdata-zk.json @@ -53,7 +53,7 @@ ], "service": "api@internal", "rule": "PathPrefix(`/api`)", - "priority": 2147483646, + "priority": 9223372036854775806, "status": "enabled", "using": [ "traefik" @@ -69,7 +69,7 @@ ], "service": "dashboard@internal", "rule": "PathPrefix(`/`)", - "priority": 2147483645, + "priority": 9223372036854775805, "status": "enabled", "using": [ "traefik" diff --git a/pkg/config/static/entrypoints.go b/pkg/config/static/entrypoints.go index b2243aa3f..905d74961 100644 --- a/pkg/config/static/entrypoints.go +++ b/pkg/config/static/entrypoints.go @@ -95,7 +95,7 @@ type RedirectEntryPoint struct { func (r *RedirectEntryPoint) SetDefaults() { r.Scheme = "https" r.Permanent = true - r.Priority = math.MaxInt32 - 1 + r.Priority = math.MaxInt - 1 } // TLSConfig is the default TLS configuration for all the routers associated to the concerned entry point. diff --git a/pkg/provider/traefik/fixtures/api_insecure_with_dashboard.json b/pkg/provider/traefik/fixtures/api_insecure_with_dashboard.json index 992a447d1..351fe168d 100644 --- a/pkg/provider/traefik/fixtures/api_insecure_with_dashboard.json +++ b/pkg/provider/traefik/fixtures/api_insecure_with_dashboard.json @@ -7,7 +7,7 @@ ], "service": "api@internal", "rule": "PathPrefix(`/api`)", - "priority": 2147483646 + "priority": 9223372036854775806 }, "dashboard": { "entryPoints": [ @@ -19,7 +19,7 @@ ], "service": "dashboard@internal", "rule": "PathPrefix(`/`)", - "priority": 2147483645 + "priority": 9223372036854775805 } }, "middlewares": { @@ -47,4 +47,4 @@ }, "tcp": {}, "tls": {} -} \ No newline at end of file +} diff --git a/pkg/provider/traefik/fixtures/api_insecure_without_dashboard.json b/pkg/provider/traefik/fixtures/api_insecure_without_dashboard.json index 994fcf3af..9a98c0a1d 100644 --- a/pkg/provider/traefik/fixtures/api_insecure_without_dashboard.json +++ b/pkg/provider/traefik/fixtures/api_insecure_without_dashboard.json @@ -7,7 +7,7 @@ ], "service": "api@internal", "rule": "PathPrefix(`/api`)", - "priority": 2147483646 + "priority": 9223372036854775806 } }, "services": { @@ -17,4 +17,4 @@ }, "tcp": {}, "tls": {} -} \ No newline at end of file +} diff --git a/pkg/provider/traefik/fixtures/full_configuration.json b/pkg/provider/traefik/fixtures/full_configuration.json index f09614e2e..ed03dda48 100644 --- a/pkg/provider/traefik/fixtures/full_configuration.json +++ b/pkg/provider/traefik/fixtures/full_configuration.json @@ -7,7 +7,7 @@ ], "service": "api@internal", "rule": "PathPrefix(`/api`)", - "priority": 2147483646 + "priority": 9223372036854775806 }, "dashboard": { "entryPoints": [ @@ -19,7 +19,7 @@ ], "service": "dashboard@internal", "rule": "PathPrefix(`/`)", - "priority": 2147483645 + "priority": 9223372036854775805 }, "debug": { "entryPoints": [ @@ -27,7 +27,7 @@ ], "service": "api@internal", "rule": "PathPrefix(`/debug`)", - "priority": 2147483646 + "priority": 9223372036854775806 }, "ping": { "entryPoints": [ @@ -35,7 +35,7 @@ ], "service": "ping@internal", "rule": "PathPrefix(`/ping`)", - "priority": 2147483647 + "priority": 9223372036854775807 }, "prometheus": { "entryPoints": [ @@ -43,7 +43,7 @@ ], "service": "prometheus@internal", "rule": "PathPrefix(`/metrics`)", - "priority": 2147483647 + "priority": 9223372036854775807 }, "rest": { "entryPoints": [ @@ -51,7 +51,7 @@ ], "service": "rest@internal", "rule": "PathPrefix(`/api/providers`)", - "priority": 2147483647 + "priority": 9223372036854775807 } }, "middlewares": { @@ -82,4 +82,4 @@ }, "tcp": {}, "tls": {} -} \ No newline at end of file +} diff --git a/pkg/provider/traefik/fixtures/ping_simple.json b/pkg/provider/traefik/fixtures/ping_simple.json index 3ee3b4050..6f159dce5 100644 --- a/pkg/provider/traefik/fixtures/ping_simple.json +++ b/pkg/provider/traefik/fixtures/ping_simple.json @@ -7,7 +7,7 @@ ], "service": "ping@internal", "rule": "PathPrefix(`/ping`)", - "priority": 2147483647 + "priority": 9223372036854775807 } }, "services": { @@ -17,4 +17,4 @@ }, "tcp": {}, "tls": {} -} \ No newline at end of file +} diff --git a/pkg/provider/traefik/fixtures/prometheus_simple.json b/pkg/provider/traefik/fixtures/prometheus_simple.json index 3c856804f..b636b4569 100644 --- a/pkg/provider/traefik/fixtures/prometheus_simple.json +++ b/pkg/provider/traefik/fixtures/prometheus_simple.json @@ -7,7 +7,7 @@ ], "service": "prometheus@internal", "rule": "PathPrefix(`/metrics`)", - "priority": 2147483647 + "priority": 9223372036854775807 } }, "services": { @@ -17,4 +17,4 @@ }, "tcp": {}, "tls": {} -} \ No newline at end of file +} diff --git a/pkg/provider/traefik/fixtures/rest_insecure.json b/pkg/provider/traefik/fixtures/rest_insecure.json index 7952359f3..e11a84e77 100644 --- a/pkg/provider/traefik/fixtures/rest_insecure.json +++ b/pkg/provider/traefik/fixtures/rest_insecure.json @@ -7,7 +7,7 @@ ], "service": "rest@internal", "rule": "PathPrefix(`/api/providers`)", - "priority": 2147483647 + "priority": 9223372036854775807 } }, "services": { @@ -17,4 +17,4 @@ }, "tcp": {}, "tls": {} -} \ No newline at end of file +} diff --git a/pkg/provider/traefik/internal.go b/pkg/provider/traefik/internal.go index 47d2c3023..83bfee8bc 100644 --- a/pkg/provider/traefik/internal.go +++ b/pkg/provider/traefik/internal.go @@ -104,7 +104,7 @@ func (i *Provider) acme(cfg *dynamic.Configuration) { Rule: "PathPrefix(`/.well-known/acme-challenge/`)", EntryPoints: eps, Service: "acme-http@internal", - Priority: math.MaxInt32, + Priority: math.MaxInt, } cfg.HTTP.Routers["acme-http"] = rt @@ -218,7 +218,7 @@ func (i *Provider) apiConfiguration(cfg *dynamic.Configuration) { cfg.HTTP.Routers["api"] = &dynamic.Router{ EntryPoints: []string{defaultInternalEntryPointName}, Service: "api@internal", - Priority: math.MaxInt32 - 1, + Priority: math.MaxInt - 1, Rule: "PathPrefix(`/api`)", } @@ -226,7 +226,7 @@ func (i *Provider) apiConfiguration(cfg *dynamic.Configuration) { cfg.HTTP.Routers["dashboard"] = &dynamic.Router{ EntryPoints: []string{defaultInternalEntryPointName}, Service: "dashboard@internal", - Priority: math.MaxInt32 - 2, + Priority: math.MaxInt - 2, Rule: "PathPrefix(`/`)", Middlewares: []string{"dashboard_redirect@internal", "dashboard_stripprefix@internal"}, } @@ -247,7 +247,7 @@ func (i *Provider) apiConfiguration(cfg *dynamic.Configuration) { cfg.HTTP.Routers["debug"] = &dynamic.Router{ EntryPoints: []string{defaultInternalEntryPointName}, Service: "api@internal", - Priority: math.MaxInt32 - 1, + Priority: math.MaxInt - 1, Rule: "PathPrefix(`/debug`)", } } @@ -269,7 +269,7 @@ func (i *Provider) pingConfiguration(cfg *dynamic.Configuration) { cfg.HTTP.Routers["ping"] = &dynamic.Router{ EntryPoints: []string{i.staticCfg.Ping.EntryPoint}, Service: "ping@internal", - Priority: math.MaxInt32, + Priority: math.MaxInt, Rule: "PathPrefix(`/ping`)", } } @@ -286,7 +286,7 @@ func (i *Provider) restConfiguration(cfg *dynamic.Configuration) { cfg.HTTP.Routers["rest"] = &dynamic.Router{ EntryPoints: []string{defaultInternalEntryPointName}, Service: "rest@internal", - Priority: math.MaxInt32, + Priority: math.MaxInt, Rule: "PathPrefix(`/api/providers`)", } } @@ -303,7 +303,7 @@ func (i *Provider) prometheusConfiguration(cfg *dynamic.Configuration) { cfg.HTTP.Routers["prometheus"] = &dynamic.Router{ EntryPoints: []string{i.staticCfg.Metrics.Prometheus.EntryPoint}, Service: "prometheus@internal", - Priority: math.MaxInt32, + Priority: math.MaxInt, Rule: "PathPrefix(`/metrics`)", } } From b931c8ae9b660188234b36941b809cbb09eedf51 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Fri, 16 Feb 2024 09:54:04 +0100 Subject: [PATCH 04/19] Update releases page --- docs/content/deprecation/releases.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/content/deprecation/releases.md b/docs/content/deprecation/releases.md index 1e73eda6d..78d6a86ce 100644 --- a/docs/content/deprecation/releases.md +++ b/docs/content/deprecation/releases.md @@ -6,7 +6,8 @@ Below is a non-exhaustive list of versions and their maintenance status: | Version | Release Date | Active Support | Security Support | |---------|--------------|--------------------|------------------| -| 2.10 | Apr 24, 2023 | Yes | Yes | +| 2.11 | Feb 12, 2023 | Yes | Yes | +| 2.10 | Apr 24, 2023 | Ended Feb 12, 2023 | No | | 2.9 | Oct 03, 2022 | Ended Apr 24, 2023 | No | | 2.8 | Jun 29, 2022 | Ended Oct 03, 2022 | No | | 2.7 | May 24, 2022 | Ended Jun 29, 2022 | No | From 538f780a85fd2a3acab2cb7edd6659474019357d Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Fri, 16 Feb 2024 10:08:04 +0100 Subject: [PATCH 05/19] Update goreleaser configuration --- .goreleaser.yml.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yml.tmpl b/.goreleaser.yml.tmpl index f469b52c5..acb524a85 100644 --- a/.goreleaser.yml.tmpl +++ b/.goreleaser.yml.tmpl @@ -46,7 +46,7 @@ builds: goarch: arm changelog: - skip: true + disable: true archives: - id: traefik From 1034646ae255e619b7f6a3e3a5def39083c9fc9c Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Mon, 19 Feb 2024 14:46:03 +0100 Subject: [PATCH 06/19] Update releases page --- docs/content/deprecation/releases.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/deprecation/releases.md b/docs/content/deprecation/releases.md index 78d6a86ce..3cfe9ddff 100644 --- a/docs/content/deprecation/releases.md +++ b/docs/content/deprecation/releases.md @@ -6,8 +6,8 @@ Below is a non-exhaustive list of versions and their maintenance status: | Version | Release Date | Active Support | Security Support | |---------|--------------|--------------------|------------------| -| 2.11 | Feb 12, 2023 | Yes | Yes | -| 2.10 | Apr 24, 2023 | Ended Feb 12, 2023 | No | +| 2.11 | Feb 12, 2024 | Yes | Yes | +| 2.10 | Apr 24, 2023 | Ended Feb 12, 2024 | No | | 2.9 | Oct 03, 2022 | Ended Apr 24, 2023 | No | | 2.8 | Jun 29, 2022 | Ended Oct 03, 2022 | No | | 2.7 | May 24, 2022 | Ended Jun 29, 2022 | No | From 88a2020817e97de53b324198346e4e02773c9444 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Mon, 19 Feb 2024 15:44:03 +0100 Subject: [PATCH 07/19] chore: update linter --- .github/workflows/validate.yaml | 2 +- .golangci.yml | 2 +- .semaphore/semaphore.yml | 2 +- cmd/internal/gen/centrifuge.go | 2 +- integration/conf_throttling_test.go | 2 +- integration/healthcheck_test.go | 14 ++++++------ integration/integration_test.go | 2 +- integration/simple_test.go | 16 +++++++------- integration/tcp_test.go | 2 +- integration/udp_test.go | 2 +- internal/gendoc.go | 2 +- pkg/api/criterion.go | 11 ++++------ pkg/api/handler.go | 2 +- pkg/api/handler_entrypoint_test.go | 2 +- pkg/api/handler_http_test.go | 2 +- pkg/api/handler_overview.go | 6 ++--- pkg/collector/hydratation/hydration.go | 6 ++--- pkg/config/kv/kv.go | 2 +- pkg/middlewares/accesslog/logger_test.go | 2 +- pkg/middlewares/capture/capture_test.go | 4 ++-- pkg/middlewares/compress/compress_test.go | 4 ++-- .../empty_backend_handler_test.go | 2 +- pkg/middlewares/metrics/metrics.go | 11 +++++----- .../requestdecorator/hostresolver.go | 2 +- pkg/middlewares/retry/retry_test.go | 2 +- pkg/muxer/http/mux.go | 10 +++------ pkg/muxer/tcp/mux.go | 15 +++++-------- pkg/provider/acme/challenge_tls.go | 13 ++--------- pkg/provider/acme/provider.go | 4 ++-- pkg/provider/constraints/constraints_tags.go | 18 +++++---------- pkg/provider/consulcatalog/config_test.go | 4 ++-- pkg/provider/docker/config_test.go | 4 ++-- pkg/provider/ecs/config_test.go | 4 ++-- pkg/provider/ecs/ecs.go | 12 +++++----- pkg/provider/ecs/ecs_test.go | 2 +- pkg/provider/kubernetes/crd/client.go | 9 +++----- pkg/provider/kubernetes/gateway/client.go | 9 +++----- pkg/provider/kubernetes/ingress/client.go | 9 +++----- pkg/provider/kubernetes/ingress/kubernetes.go | 11 ++++------ pkg/provider/rancher/config_test.go | 2 +- pkg/redactor/redactor.go | 6 ++--- pkg/server/aggregator.go | 14 +++--------- pkg/server/configurationwatcher_test.go | 2 +- pkg/server/middleware/middlewares.go | 12 ++-------- pkg/server/middleware/tcp/middlewares.go | 12 ++-------- pkg/server/router/router_test.go | 4 ++-- pkg/server/server_entrypoint_tcp_test.go | 4 ++-- .../loadbalancer/mirror/mirror_test.go | 6 ++--- .../service/loadbalancer/wrr/wrr_test.go | 22 +++++++++---------- pkg/server/service/proxy_test.go | 2 +- pkg/server/service/roundtripper.go | 10 ++++----- pkg/server/service/roundtripper_test.go | 2 +- pkg/server/service/service.go | 2 +- pkg/tcp/wrr_load_balancer_test.go | 2 +- pkg/tls/tlsmanager.go | 13 ++--------- pkg/types/http_code_range.go | 10 ++++----- pkg/udp/conn_test.go | 2 +- 57 files changed, 139 insertions(+), 218 deletions(-) diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index 82570d790..076a36b64 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -7,7 +7,7 @@ on: env: GO_VERSION: '1.22' - GOLANGCI_LINT_VERSION: v1.56.0 + GOLANGCI_LINT_VERSION: v1.56.2 MISSSPELL_VERSION: v0.4.1 jobs: diff --git a/.golangci.yml b/.golangci.yml index b8a1ceaaa..1a7860b91 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -225,7 +225,7 @@ issues: - 'SA1019: c.Providers.ConsulCatalog.Namespace is deprecated' - 'SA1019: c.Providers.Consul.Namespace is deprecated' - 'SA1019: c.Providers.Nomad.Namespace is deprecated' - - 'fmt.Sprintf can be replaced with string addition' + - 'fmt.Sprintf can be replaced with string' exclude-rules: - path: '(.+)_test.go' linters: diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml index 5bbb5bf57..e45bca92c 100644 --- a/.semaphore/semaphore.yml +++ b/.semaphore/semaphore.yml @@ -25,7 +25,7 @@ global_job_config: - export "PATH=${GOPATH}/bin:${PATH}" - mkdir -vp "${SEMAPHORE_GIT_DIR}" "${GOPATH}/bin" - export GOPROXY=https://proxy.golang.org,direct - - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin" v1.56.0 + - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin" v1.56.2 - curl -sSfL https://gist.githubusercontent.com/traefiker/6d7ac019c11d011e4f131bb2cca8900e/raw/goreleaser.sh | bash -s -- -b "${GOPATH}/bin" - checkout - cache restore traefik-$(checksum go.sum) diff --git a/cmd/internal/gen/centrifuge.go b/cmd/internal/gen/centrifuge.go index df5d46fd8..2c0f6e634 100644 --- a/cmd/internal/gen/centrifuge.go +++ b/cmd/internal/gen/centrifuge.go @@ -160,7 +160,7 @@ func (c Centrifuge) writeStruct(name string, obj *types.Struct, rootPkg string, b := strings.Builder{} b.WriteString(fmt.Sprintf("type %s struct {\n", name)) - for i := 0; i < obj.NumFields(); i++ { + for i := range obj.NumFields() { field := obj.Field(i) if !field.Exported() { diff --git a/integration/conf_throttling_test.go b/integration/conf_throttling_test.go index 7e29c039f..162aff5d9 100644 --- a/integration/conf_throttling_test.go +++ b/integration/conf_throttling_test.go @@ -67,7 +67,7 @@ func (s *ThrottlingSuite) TestThrottleConfReload() { confChanges := 10 - for i := 0; i < confChanges; i++ { + for i := range confChanges { config.HTTP.Routers[fmt.Sprintf("routerHTTP%d", i)] = router data, err := json.Marshal(config) require.NoError(s.T(), err) diff --git a/integration/healthcheck_test.go b/integration/healthcheck_test.go index 4e6279c97..6f14b048b 100644 --- a/integration/healthcheck_test.go +++ b/integration/healthcheck_test.go @@ -312,7 +312,7 @@ func (s *HealthCheckSuite) TestPropagate() { // Verify load-balancing on root still works, and that we're getting an alternation between wsp2, and wsp4. reachedServers := make(map[string]int) - for i := 0; i < 4; i++ { + for range 4 { resp, err := client.Do(rootReq) require.NoError(s.T(), err) @@ -352,7 +352,7 @@ func (s *HealthCheckSuite) TestPropagate() { // Verify load-balancing on foo still works, and that we're getting wsp2, wsp2, wsp2, wsp2, etc. want := `IP: ` + s.whoami2IP - for i := 0; i < 4; i++ { + for range 4 { resp, err := client.Do(fooReq) require.NoError(s.T(), err) @@ -368,7 +368,7 @@ func (s *HealthCheckSuite) TestPropagate() { // Verify load-balancing on bar still works, and that we're getting wsp2, wsp2, wsp2, wsp2, etc. want = `IP: ` + s.whoami2IP - for i := 0; i < 4; i++ { + for range 4 { resp, err := client.Do(barReq) require.NoError(s.T(), err) @@ -390,7 +390,7 @@ func (s *HealthCheckSuite) TestPropagate() { try.Sleep(time.Second) // Verify that everything is down, and that we get 503s everywhere. - for i := 0; i < 2; i++ { + for range 2 { resp, err := client.Do(rootReq) require.NoError(s.T(), err) assert.Equal(s.T(), http.StatusServiceUnavailable, resp.StatusCode) @@ -417,7 +417,7 @@ func (s *HealthCheckSuite) TestPropagate() { // Verify everything is up on root router. reachedServers = make(map[string]int) - for i := 0; i < 4; i++ { + for range 4 { resp, err := client.Do(rootReq) require.NoError(s.T(), err) @@ -452,7 +452,7 @@ func (s *HealthCheckSuite) TestPropagate() { // Verify everything is up on foo router. reachedServers = make(map[string]int) - for i := 0; i < 4; i++ { + for range 4 { resp, err := client.Do(fooReq) require.NoError(s.T(), err) @@ -487,7 +487,7 @@ func (s *HealthCheckSuite) TestPropagate() { // Verify everything is up on bar router. reachedServers = make(map[string]int) - for i := 0; i < 4; i++ { + for range 4 { resp, err := client.Do(barReq) require.NoError(s.T(), err) diff --git a/integration/integration_test.go b/integration/integration_test.go index 4ce934535..0626724da 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -239,7 +239,7 @@ func (s *BaseSuite) createComposeProject(name string) { } if containerConfig.Deploy.Replicas > 0 { - for i := 0; i < containerConfig.Deploy.Replicas; i++ { + for i := range containerConfig.Deploy.Replicas { id = fmt.Sprintf("%s-%d", id, i+1) con, err := s.createContainer(ctx, containerConfig, id, mounts) require.NoError(s.T(), err) diff --git a/integration/simple_test.go b/integration/simple_test.go index 76305bbbc..fc5936069 100644 --- a/integration/simple_test.go +++ b/integration/simple_test.go @@ -307,7 +307,7 @@ func (s *SimpleSuite) TestMetricsPrometheusTwoRoutersOneService() { require.NoError(s.T(), err) // adding a loop to test if metrics are not deleted - for i := 0; i < 10; i++ { + for range 10 { request, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8080/metrics", nil) require.NoError(s.T(), err) @@ -771,7 +771,7 @@ func (s *SimpleSuite) TestWRR() { require.NoError(s.T(), err) repartition := map[string]int{} - for i := 0; i < 4; i++ { + for range 4 { req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/whoami", nil) require.NoError(s.T(), err) @@ -817,7 +817,7 @@ func (s *SimpleSuite) TestWRRSticky() { req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/whoami", nil) require.NoError(s.T(), err) - for i := 0; i < 4; i++ { + for range 4 { response, err := http.DefaultClient.Do(req) require.NoError(s.T(), err) assert.Equal(s.T(), http.StatusOK, response.StatusCode) @@ -873,7 +873,7 @@ func (s *SimpleSuite) TestMirror() { req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/whoami", nil) require.NoError(s.T(), err) - for i := 0; i < 10; i++ { + for range 10 { response, err := http.DefaultClient.Do(req) require.NoError(s.T(), err) assert.Equal(s.T(), http.StatusOK, response.StatusCode) @@ -944,7 +944,7 @@ func (s *SimpleSuite) TestMirrorWithBody() { req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/whoami", bytes.NewBuffer(body20)) require.NoError(s.T(), err) req.Header.Set("Size", "20") - for i := 0; i < 10; i++ { + for range 10 { response, err := http.DefaultClient.Do(req) require.NoError(s.T(), err) assert.Equal(s.T(), http.StatusOK, response.StatusCode) @@ -965,7 +965,7 @@ func (s *SimpleSuite) TestMirrorWithBody() { req, err = http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/whoamiWithMaxBody", bytes.NewBuffer(body5)) require.NoError(s.T(), err) req.Header.Set("Size", "5") - for i := 0; i < 10; i++ { + for range 10 { response, err := http.DefaultClient.Do(req) require.NoError(s.T(), err) assert.Equal(s.T(), http.StatusOK, response.StatusCode) @@ -986,7 +986,7 @@ func (s *SimpleSuite) TestMirrorWithBody() { req, err = http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/whoamiWithMaxBody", bytes.NewBuffer(body20)) require.NoError(s.T(), err) req.Header.Set("Size", "20") - for i := 0; i < 10; i++ { + for range 10 { response, err := http.DefaultClient.Do(req) require.NoError(s.T(), err) assert.Equal(s.T(), http.StatusOK, response.StatusCode) @@ -1032,7 +1032,7 @@ func (s *SimpleSuite) TestMirrorCanceled() { err := try.GetRequest("http://127.0.0.1:8080/api/http/services", 1000*time.Millisecond, try.BodyContains("mirror1", "mirror2", "service1")) require.NoError(s.T(), err) - for i := 0; i < 5; i++ { + for range 5 { req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/whoami", nil) require.NoError(s.T(), err) diff --git a/integration/tcp_test.go b/integration/tcp_test.go index b755f8b12..30a6e0bee 100644 --- a/integration/tcp_test.go +++ b/integration/tcp_test.go @@ -263,7 +263,7 @@ func (s *TCPSuite) TestWRR() { require.NoError(s.T(), err) call := map[string]int{} - for i := 0; i < 4; i++ { + for range 4 { // Traefik passes through, termination handled by whoami-b or whoami-bb out, err := guessWhoTLSPassthrough("127.0.0.1:8093", "whoami-b.test") require.NoError(s.T(), err) diff --git a/integration/udp_test.go b/integration/udp_test.go index 58951b78d..770785f99 100644 --- a/integration/udp_test.go +++ b/integration/udp_test.go @@ -82,7 +82,7 @@ func (s *UDPSuite) TestWRR() { stop := make(chan struct{}) go func() { call := map[string]int{} - for i := 0; i < 8; i++ { + for range 8 { out, err := guessWhoUDP("127.0.0.1:8093") require.NoError(s.T(), err) switch { diff --git a/internal/gendoc.go b/internal/gendoc.go index d27c0fe3d..76f650582 100644 --- a/internal/gendoc.go +++ b/internal/gendoc.go @@ -223,7 +223,7 @@ func clean(element any) { valueSvcRoot := valSvcs.MapIndex(key).Elem() var svcFieldNames []string - for i := 0; i < valueSvcRoot.NumField(); i++ { + for i := range valueSvcRoot.NumField() { svcFieldNames = append(svcFieldNames, valueSvcRoot.Type().Field(i).Name) } diff --git a/pkg/api/criterion.go b/pkg/api/criterion.go index d81a9f717..cd173f532 100644 --- a/pkg/api/criterion.go +++ b/pkg/api/criterion.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "net/url" + "slices" "strconv" "strings" ) @@ -50,13 +51,9 @@ func (c *searchCriterion) searchIn(values ...string) bool { return true } - for _, v := range values { - if strings.Contains(strings.ToLower(v), strings.ToLower(c.Search)) { - return true - } - } - - return false + return slices.ContainsFunc(values, func(v string) bool { + return strings.Contains(strings.ToLower(v), strings.ToLower(c.Search)) + }) } func pagination(request *http.Request, max int) (pageInfo, error) { diff --git a/pkg/api/handler.go b/pkg/api/handler.go index df4db9f98..18cc7c7ba 100644 --- a/pkg/api/handler.go +++ b/pkg/api/handler.go @@ -149,7 +149,7 @@ func getProviderName(id string) string { func extractType(element interface{}) string { v := reflect.ValueOf(element).Elem() - for i := 0; i < v.NumField(); i++ { + for i := range v.NumField() { field := v.Field(i) if field.Kind() == reflect.Map && field.Type().Elem() == reflect.TypeOf(dynamic.PluginConf{}) { diff --git a/pkg/api/handler_entrypoint_test.go b/pkg/api/handler_entrypoint_test.go index 5172e4689..36010cebe 100644 --- a/pkg/api/handler_entrypoint_test.go +++ b/pkg/api/handler_entrypoint_test.go @@ -256,7 +256,7 @@ func TestHandler_EntryPoints(t *testing.T) { func generateEntryPoints(nb int) map[string]*static.EntryPoint { eps := make(map[string]*static.EntryPoint, nb) - for i := 0; i < nb; i++ { + for i := range nb { eps[fmt.Sprintf("ep%2d", i)] = &static.EntryPoint{ Address: ":" + strconv.Itoa(i), } diff --git a/pkg/api/handler_http_test.go b/pkg/api/handler_http_test.go index d7f905c5d..b814c69ab 100644 --- a/pkg/api/handler_http_test.go +++ b/pkg/api/handler_http_test.go @@ -972,7 +972,7 @@ func TestHandler_HTTP(t *testing.T) { func generateHTTPRouters(nbRouters int) map[string]*runtime.RouterInfo { routers := make(map[string]*runtime.RouterInfo, nbRouters) - for i := 0; i < nbRouters; i++ { + for i := range nbRouters { routers[fmt.Sprintf("bar%2d@myprovider", i)] = &runtime.RouterInfo{ Router: &dynamic.Router{ EntryPoints: []string{"web"}, diff --git a/pkg/api/handler_overview.go b/pkg/api/handler_overview.go index 4e6485e7d..98c350dfb 100644 --- a/pkg/api/handler_overview.go +++ b/pkg/api/handler_overview.go @@ -226,7 +226,7 @@ func getProviders(conf static.Configuration) []string { var providers []string v := reflect.ValueOf(conf.Providers).Elem() - for i := 0; i < v.NumField(); i++ { + for i := range v.NumField() { field := v.Field(i) if field.Kind() == reflect.Ptr && field.Elem().Kind() == reflect.Struct { if !field.IsNil() { @@ -256,7 +256,7 @@ func getMetrics(conf static.Configuration) string { } v := reflect.ValueOf(conf.Metrics).Elem() - for i := 0; i < v.NumField(); i++ { + for i := range v.NumField() { field := v.Field(i) if field.Kind() == reflect.Ptr && field.Elem().Kind() == reflect.Struct { if !field.IsNil() { @@ -274,7 +274,7 @@ func getTracing(conf static.Configuration) string { } v := reflect.ValueOf(conf.Tracing).Elem() - for i := 0; i < v.NumField(); i++ { + for i := range v.NumField() { field := v.Field(i) if field.Kind() == reflect.Ptr && field.Elem().Kind() == reflect.Struct { if !field.IsNil() { diff --git a/pkg/collector/hydratation/hydration.go b/pkg/collector/hydratation/hydration.go index a5ec52dee..40736f046 100644 --- a/pkg/collector/hydratation/hydration.go +++ b/pkg/collector/hydratation/hydration.go @@ -93,7 +93,7 @@ func setTyped(field reflect.Value, i interface{}) { func setMap(field reflect.Value) error { field.Set(reflect.MakeMap(field.Type())) - for i := 0; i < mapItemNumber; i++ { + for i := range mapItemNumber { baseKeyName := makeKeyName(field.Type().Elem()) key := reflect.ValueOf(fmt.Sprintf("%s%d", baseKeyName, i)) @@ -125,7 +125,7 @@ func makeKeyName(typ reflect.Type) string { } func setStruct(field reflect.Value) error { - for i := 0; i < field.NumField(); i++ { + for i := range field.NumField() { fld := field.Field(i) stFld := field.Type().Field(i) @@ -142,7 +142,7 @@ func setStruct(field reflect.Value) error { func setSlice(field reflect.Value) error { field.Set(reflect.MakeSlice(field.Type(), sliceItemNumber, sliceItemNumber)) - for j := 0; j < field.Len(); j++ { + for j := range field.Len() { if err := fill(field.Index(j)); err != nil { return err } diff --git a/pkg/config/kv/kv.go b/pkg/config/kv/kv.go index 8af4855e3..ad467b00d 100644 --- a/pkg/config/kv/kv.go +++ b/pkg/config/kv/kv.go @@ -55,7 +55,7 @@ func getFieldNames(rootName string, rootType reflect.Type) []string { return nil } - for i := 0; i < rootType.NumField(); i++ { + for i := range rootType.NumField() { field := rootType.Field(i) if !parser.IsExported(field) { diff --git a/pkg/middlewares/accesslog/logger_test.go b/pkg/middlewares/accesslog/logger_test.go index a70e2cc6f..b599e3e8d 100644 --- a/pkg/middlewares/accesslog/logger_test.go +++ b/pkg/middlewares/accesslog/logger_test.go @@ -74,7 +74,7 @@ func TestLogRotation(t *testing.T) { halfDone := make(chan bool) writeDone := make(chan bool) go func() { - for i := 0; i < iterations; i++ { + for i := range iterations { handler.ServeHTTP(recorder, req) if i == iterations/2 { halfDone <- true diff --git a/pkg/middlewares/capture/capture_test.go b/pkg/middlewares/capture/capture_test.go index 776dd74d8..2254b0fea 100644 --- a/pkg/middlewares/capture/capture_test.go +++ b/pkg/middlewares/capture/capture_test.go @@ -149,7 +149,7 @@ func BenchmarkCapture(b *testing.B) { b.ReportAllocs() b.SetBytes(int64(test.size)) b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { runBenchmark(b, test.size, req, handlers) } }) @@ -170,7 +170,7 @@ func runBenchmark(b *testing.B, size int, req *http.Request, handler http.Handle func generateBytes(length int) []byte { var value []byte - for i := 0; i < length; i++ { + for i := range length { value = append(value, 0x61+byte(i%26)) } return value diff --git a/pkg/middlewares/compress/compress_test.go b/pkg/middlewares/compress/compress_test.go index 10f07fda0..3bdaf9678 100644 --- a/pkg/middlewares/compress/compress_test.go +++ b/pkg/middlewares/compress/compress_test.go @@ -499,7 +499,7 @@ func BenchmarkCompress(b *testing.B) { } b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { runBenchmark(b, req, handler) } }) @@ -520,7 +520,7 @@ func runBenchmark(b *testing.B, req *http.Request, handler http.Handler) { func generateBytes(length int) []byte { var value []byte - for i := 0; i < length; i++ { + for i := range length { value = append(value, 0x61+byte(i)) } return value diff --git a/pkg/middlewares/emptybackendhandler/empty_backend_handler_test.go b/pkg/middlewares/emptybackendhandler/empty_backend_handler_test.go index 657be8201..fddb9c768 100644 --- a/pkg/middlewares/emptybackendhandler/empty_backend_handler_test.go +++ b/pkg/middlewares/emptybackendhandler/empty_backend_handler_test.go @@ -58,7 +58,7 @@ func (lb *healthCheckLoadBalancer) ServeHTTP(w http.ResponseWriter, r *http.Requ func (lb *healthCheckLoadBalancer) Servers() []*url.URL { servers := make([]*url.URL, lb.amountServer) - for i := 0; i < lb.amountServer; i++ { + for range lb.amountServer { servers = append(servers, testhelpers.MustParseURL("http://localhost")) } return servers diff --git a/pkg/middlewares/metrics/metrics.go b/pkg/middlewares/metrics/metrics.go index c4fc78801..3c278a9d2 100644 --- a/pkg/middlewares/metrics/metrics.go +++ b/pkg/middlewares/metrics/metrics.go @@ -3,6 +3,7 @@ package metrics import ( "context" "net/http" + "slices" "strconv" "strings" "time" @@ -175,12 +176,10 @@ func isSSERequest(req *http.Request) bool { func containsHeader(req *http.Request, name, value string) bool { items := strings.Split(req.Header.Get(name), ",") - for _, item := range items { - if value == strings.ToLower(strings.TrimSpace(item)) { - return true - } - } - return false + + return slices.ContainsFunc(items, func(item string) bool { + return value == strings.ToLower(strings.TrimSpace(item)) + }) } // getMethod returns the request's method. diff --git a/pkg/middlewares/requestdecorator/hostresolver.go b/pkg/middlewares/requestdecorator/hostresolver.go index d08768175..3f6e4f882 100644 --- a/pkg/middlewares/requestdecorator/hostresolver.go +++ b/pkg/middlewares/requestdecorator/hostresolver.go @@ -49,7 +49,7 @@ func (hr *Resolver) CNAMEFlatten(ctx context.Context, host string) string { logger := log.FromContext(ctx) cacheDuration := 0 * time.Second - for depth := 0; depth < hr.ResolvDepth; depth++ { + for depth := range hr.ResolvDepth { resolv, err := cnameResolve(ctx, request, hr.ResolvConfig) if err != nil { logger.Error(err) diff --git a/pkg/middlewares/retry/retry_test.go b/pkg/middlewares/retry/retry_test.go index 8da95f8e1..5645e007c 100644 --- a/pkg/middlewares/retry/retry_test.go +++ b/pkg/middlewares/retry/retry_test.go @@ -203,7 +203,7 @@ func TestMultipleRetriesShouldNotLooseHeaders(t *testing.T) { } // Validate that we don't have headers from previous attempts - for i := 0; i < attempt; i++ { + for i := range attempt { headerName := fmt.Sprintf("X-Foo-Test-%d", i) headerValue = responseRecorder.Header().Get("headerName") if headerValue != "" { diff --git a/pkg/muxer/http/mux.go b/pkg/muxer/http/mux.go index fefab67a9..ca011b79c 100644 --- a/pkg/muxer/http/mux.go +++ b/pkg/muxer/http/mux.go @@ -324,11 +324,7 @@ func addRuleOnRoute(route *mux.Route, rule *rules.Tree) error { // IsASCII checks if the given string contains only ASCII characters. func IsASCII(s string) bool { - for i := 0; i < len(s); i++ { - if s[i] >= utf8.RuneSelf { - return false - } - } - - return true + return !strings.ContainsFunc(s, func(r rune) bool { + return r >= utf8.RuneSelf + }) } diff --git a/pkg/muxer/tcp/mux.go b/pkg/muxer/tcp/mux.go index 592738b24..e50b78899 100644 --- a/pkg/muxer/tcp/mux.go +++ b/pkg/muxer/tcp/mux.go @@ -6,6 +6,7 @@ import ( "fmt" "net" "regexp" + "slices" "sort" "strconv" "strings" @@ -301,15 +302,9 @@ func alpn(tree *matchersTree, protos ...string) error { } tree.matcher = func(meta ConnData) bool { - for _, proto := range meta.alpnProtos { - for _, filter := range protos { - if proto == filter { - return true - } - } - } - - return false + return slices.ContainsFunc(meta.alpnProtos, func(proto string) bool { + return slices.Contains(protos, proto) + }) } return nil @@ -469,7 +464,7 @@ func varGroupName(idx int) string { func braceIndices(s string) ([]int, error) { var level, idx int var idxs []int - for i := 0; i < len(s); i++ { + for i := range len(s) { switch s[i] { case '{': if level++; level == 1 { diff --git a/pkg/provider/acme/challenge_tls.go b/pkg/provider/acme/challenge_tls.go index 6249bc52e..3513d03a3 100644 --- a/pkg/provider/acme/challenge_tls.go +++ b/pkg/provider/acme/challenge_tls.go @@ -2,6 +2,7 @@ package acme import ( "fmt" + "slices" "sync" "time" @@ -118,7 +119,7 @@ func (c *ChallengeTLSALPN) ListenConfiguration(conf dynamic.Configuration) { c.muChans.Lock() for _, certificate := range conf.TLS.Certificates { - if !containsACMETLS1(certificate.Stores) { + if !slices.Contains(certificate.Stores, tlsalpn01.ACMETLS1Protocol) { continue } @@ -161,13 +162,3 @@ func createMessage(certs map[string]*Certificate) dynamic.Message { return conf } - -func containsACMETLS1(stores []string) bool { - for _, store := range stores { - if store == tlsalpn01.ACMETLS1Protocol { - return true - } - } - - return false -} diff --git a/pkg/provider/acme/provider.go b/pkg/provider/acme/provider.go index 451ee83b1..bdb6ea02a 100644 --- a/pkg/provider/acme/provider.go +++ b/pkg/provider/acme/provider.go @@ -424,7 +424,7 @@ func (p *Provider) watchNewDomains(ctx context.Context) { if len(route.TLS.Domains) > 0 { domains := deleteUnnecessaryDomains(ctxRouter, route.TLS.Domains) - for i := 0; i < len(domains); i++ { + for i := range len(domains) { domain := domains[i] safe.Go(func() { dom, cert, err := p.resolveCertificate(ctx, domain, traefiktls.DefaultTLSStoreName) @@ -461,7 +461,7 @@ func (p *Provider) watchNewDomains(ctx context.Context) { if len(route.TLS.Domains) > 0 { domains := deleteUnnecessaryDomains(ctxRouter, route.TLS.Domains) - for i := 0; i < len(domains); i++ { + for i := range len(domains) { domain := domains[i] safe.Go(func() { dom, cert, err := p.resolveCertificate(ctx, domain, traefiktls.DefaultTLSStoreName) diff --git a/pkg/provider/constraints/constraints_tags.go b/pkg/provider/constraints/constraints_tags.go index cb29997a3..b61f43c5d 100644 --- a/pkg/provider/constraints/constraints_tags.go +++ b/pkg/provider/constraints/constraints_tags.go @@ -3,6 +3,7 @@ package constraints import ( "errors" "regexp" + "slices" "github.com/vulcand/predicate" ) @@ -47,12 +48,7 @@ func MatchTags(tags []string, expr string) (bool, error) { func tagFn(name string) constraintTagFunc { return func(tags []string) bool { - for _, tag := range tags { - if tag == name { - return true - } - } - return false + return slices.Contains(tags, name) } } @@ -63,13 +59,9 @@ func tagRegexFn(expr string) constraintTagFunc { return false } - for _, tag := range tags { - if exp.MatchString(tag) { - return true - } - } - - return false + return slices.ContainsFunc(tags, func(tag string) bool { + return exp.MatchString(tag) + }) } } diff --git a/pkg/provider/consulcatalog/config_test.go b/pkg/provider/consulcatalog/config_test.go index 666320404..bb6f41846 100644 --- a/pkg/provider/consulcatalog/config_test.go +++ b/pkg/provider/consulcatalog/config_test.go @@ -274,7 +274,7 @@ func TestDefaultRule(t *testing.T) { err := p.Init() require.NoError(t, err) - for i := 0; i < len(test.items); i++ { + for i := range len(test.items) { var err error test.items[i].ExtraConf, err = p.getExtraConf(test.items[i].Labels) require.NoError(t, err) @@ -2956,7 +2956,7 @@ func Test_buildConfiguration(t *testing.T) { err := p.Init() require.NoError(t, err) - for i := 0; i < len(test.items); i++ { + for i := range len(test.items) { var err error test.items[i].ExtraConf, err = p.getExtraConf(test.items[i].Labels) require.NoError(t, err) diff --git a/pkg/provider/docker/config_test.go b/pkg/provider/docker/config_test.go index cb7877226..a8fd786e1 100644 --- a/pkg/provider/docker/config_test.go +++ b/pkg/provider/docker/config_test.go @@ -361,7 +361,7 @@ func TestDefaultRule(t *testing.T) { err := p.Init() require.NoError(t, err) - for i := 0; i < len(test.containers); i++ { + for i := range len(test.containers) { var err error test.containers[i].ExtraConf, err = p.getConfiguration(test.containers[i]) require.NoError(t, err) @@ -3257,7 +3257,7 @@ func Test_buildConfiguration(t *testing.T) { err := p.Init() require.NoError(t, err) - for i := 0; i < len(test.containers); i++ { + for i := range len(test.containers) { var err error test.containers[i].ExtraConf, err = p.getConfiguration(test.containers[i]) require.NoError(t, err) diff --git a/pkg/provider/ecs/config_test.go b/pkg/provider/ecs/config_test.go index 76b18887f..e6a190213 100644 --- a/pkg/provider/ecs/config_test.go +++ b/pkg/provider/ecs/config_test.go @@ -333,7 +333,7 @@ func TestDefaultRule(t *testing.T) { err := p.Init() require.NoError(t, err) - for i := 0; i < len(test.instances); i++ { + for i := range len(test.instances) { var err error test.instances[i].ExtraConf, err = p.getConfiguration(test.instances[i]) require.NoError(t, err) @@ -2863,7 +2863,7 @@ func Test_buildConfiguration(t *testing.T) { err := p.Init() require.NoError(t, err) - for i := 0; i < len(test.containers); i++ { + for i := range len(test.containers) { var err error test.containers[i].ExtraConf, err = p.getConfiguration(test.containers[i]) require.NoError(t, err) diff --git a/pkg/provider/ecs/ecs.go b/pkg/provider/ecs/ecs.go index 8def19a85..e2edfbbc7 100644 --- a/pkg/provider/ecs/ecs.go +++ b/pkg/provider/ecs/ecs.go @@ -397,7 +397,7 @@ func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsI } func (p *Provider) lookupMiInstances(ctx context.Context, client *awsClient, clusterName *string, ecsDatas map[string]*ecs.Task) (map[string]*ssm.InstanceInformation, error) { - instanceIds := make(map[string]string) + instanceIDs := make(map[string]string) miInstances := make(map[string]*ssm.InstanceInformation) var containerInstancesArns []*string @@ -419,7 +419,7 @@ func (p *Provider) lookupMiInstances(ctx context.Context, client *awsClient, clu } for _, container := range resp.ContainerInstances { - instanceIds[aws.StringValue(container.Ec2InstanceId)] = aws.StringValue(container.ContainerInstanceArn) + instanceIDs[aws.StringValue(container.Ec2InstanceId)] = aws.StringValue(container.ContainerInstanceArn) // Disallow EC2 Instance IDs // This prevents considering EC2 instances in ECS @@ -447,7 +447,7 @@ func (p *Provider) lookupMiInstances(ctx context.Context, client *awsClient, clu if len(page.InstanceInformationList) > 0 { for _, i := range page.InstanceInformationList { if i.InstanceId != nil { - miInstances[instanceIds[aws.StringValue(i.InstanceId)]] = i + miInstances[instanceIDs[aws.StringValue(i.InstanceId)]] = i } } } @@ -463,7 +463,7 @@ func (p *Provider) lookupMiInstances(ctx context.Context, client *awsClient, clu } func (p *Provider) lookupEc2Instances(ctx context.Context, client *awsClient, clusterName *string, ecsDatas map[string]*ecs.Task) (map[string]*ec2.Instance, error) { - instanceIds := make(map[string]string) + instanceIDs := make(map[string]string) ec2Instances := make(map[string]*ec2.Instance) var containerInstancesArns []*string @@ -485,7 +485,7 @@ func (p *Provider) lookupEc2Instances(ctx context.Context, client *awsClient, cl } for _, container := range resp.ContainerInstances { - instanceIds[aws.StringValue(container.Ec2InstanceId)] = aws.StringValue(container.ContainerInstanceArn) + instanceIDs[aws.StringValue(container.Ec2InstanceId)] = aws.StringValue(container.ContainerInstanceArn) // Disallow Instance IDs of the form mi-* // This prevents considering external instances in ECS Anywhere setups // and getting InvalidInstanceID.Malformed error when calling the describe-instances endpoint. @@ -508,7 +508,7 @@ func (p *Provider) lookupEc2Instances(ctx context.Context, client *awsClient, cl for _, r := range page.Reservations { for _, i := range r.Instances { if i.InstanceId != nil { - ec2Instances[instanceIds[aws.StringValue(i.InstanceId)]] = i + ec2Instances[instanceIDs[aws.StringValue(i.InstanceId)]] = i } } } diff --git a/pkg/provider/ecs/ecs_test.go b/pkg/provider/ecs/ecs_test.go index f55510305..ede115a41 100644 --- a/pkg/provider/ecs/ecs_test.go +++ b/pkg/provider/ecs/ecs_test.go @@ -73,7 +73,7 @@ func TestChunkIDs(t *testing.T) { t.Parallel() var IDs []*string - for v := 0; v < test.count; v++ { + for range test.count { IDs = append(IDs, aws.String("a")) } diff --git a/pkg/provider/kubernetes/crd/client.go b/pkg/provider/kubernetes/crd/client.go index c678db966..97047f138 100644 --- a/pkg/provider/kubernetes/crd/client.go +++ b/pkg/provider/kubernetes/crd/client.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "runtime" + "slices" "time" "github.com/traefik/traefik/v2/pkg/log" @@ -452,12 +453,8 @@ func (c *clientWrapper) isWatchedNamespace(ns string) bool { if c.isNamespaceAll { return true } - for _, watchedNamespace := range c.watchedNamespaces { - if watchedNamespace == ns { - return true - } - } - return false + + return slices.Contains(c.watchedNamespaces, ns) } // translateNotFoundError will translate a "not found" error to a boolean return diff --git a/pkg/provider/kubernetes/gateway/client.go b/pkg/provider/kubernetes/gateway/client.go index 59f29fbb4..747f2503f 100644 --- a/pkg/provider/kubernetes/gateway/client.go +++ b/pkg/provider/kubernetes/gateway/client.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "os" + "slices" "time" "github.com/traefik/traefik/v2/pkg/log" @@ -548,10 +549,6 @@ func (c *clientWrapper) isWatchedNamespace(ns string) bool { if c.isNamespaceAll { return true } - for _, watchedNamespace := range c.watchedNamespaces { - if watchedNamespace == ns { - return true - } - } - return false + + return slices.Contains(c.watchedNamespaces, ns) } diff --git a/pkg/provider/kubernetes/ingress/client.go b/pkg/provider/kubernetes/ingress/client.go index 3d2c002f4..a0893b771 100644 --- a/pkg/provider/kubernetes/ingress/client.go +++ b/pkg/provider/kubernetes/ingress/client.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "runtime" + "slices" "time" "github.com/hashicorp/go-version" @@ -538,12 +539,8 @@ func (c *clientWrapper) isWatchedNamespace(ns string) bool { if c.isNamespaceAll { return true } - for _, watchedNamespace := range c.watchedNamespaces { - if watchedNamespace == ns { - return true - } - } - return false + + return slices.Contains(c.watchedNamespaces, ns) } // IngressClass objects are supported since Kubernetes v1.18. diff --git a/pkg/provider/kubernetes/ingress/kubernetes.go b/pkg/provider/kubernetes/ingress/kubernetes.go index 7b43ead4f..bc1f9a413 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes.go +++ b/pkg/provider/kubernetes/ingress/kubernetes.go @@ -8,6 +8,7 @@ import ( "math" "net" "os" + "slices" "sort" "strconv" "strings" @@ -412,13 +413,9 @@ func (p *Provider) updateIngressStatus(ing *netv1.Ingress, k8sClient Client) err func (p *Provider) shouldProcessIngress(ingress *netv1.Ingress, ingressClasses []*netv1.IngressClass) bool { // configuration through the new kubernetes ingressClass if ingress.Spec.IngressClassName != nil { - for _, ic := range ingressClasses { - if *ingress.Spec.IngressClassName == ic.ObjectMeta.Name { - return true - } - } - - return false + return slices.ContainsFunc(ingressClasses, func(ic *netv1.IngressClass) bool { + return *ingress.Spec.IngressClassName == ic.ObjectMeta.Name + }) } return p.IngressClass == ingress.Annotations[annotationKubernetesIngressClass] || diff --git a/pkg/provider/rancher/config_test.go b/pkg/provider/rancher/config_test.go index efab43f4a..0db7b955b 100644 --- a/pkg/provider/rancher/config_test.go +++ b/pkg/provider/rancher/config_test.go @@ -1146,7 +1146,7 @@ func Test_buildConfiguration(t *testing.T) { err := p.Init() require.NoError(t, err) - for i := 0; i < len(test.containers); i++ { + for i := range len(test.containers) { var err error test.containers[i].ExtraConf, err = p.getConfiguration(test.containers[i]) require.NoError(t, err) diff --git a/pkg/redactor/redactor.go b/pkg/redactor/redactor.go index d655a673b..ccdcc5b18 100644 --- a/pkg/redactor/redactor.go +++ b/pkg/redactor/redactor.go @@ -83,7 +83,7 @@ func doOnStruct(field reflect.Value, tag string, redactByDefault bool) error { } } case reflect.Struct: - for i := 0; i < field.NumField(); i++ { + for i := range field.NumField() { fld := field.Field(i) stField := field.Type().Field(i) if !isExported(stField) { @@ -138,7 +138,7 @@ func doOnStruct(field reflect.Value, tag string, redactByDefault bool) error { } } case reflect.Slice: - for j := 0; j < field.Len(); j++ { + for j := range field.Len() { if err := doOnStruct(field.Index(j), tag, redactByDefault); err != nil { return err } @@ -179,7 +179,7 @@ func reset(field reflect.Value, name string) error { switch field.Type().Elem().Kind() { case reflect.String: slice := reflect.MakeSlice(field.Type(), field.Len(), field.Len()) - for j := 0; j < field.Len(); j++ { + for j := range field.Len() { slice.Index(j).SetString(maskShort) } field.Set(slice) diff --git a/pkg/server/aggregator.go b/pkg/server/aggregator.go index 4b50829e8..f34e76c00 100644 --- a/pkg/server/aggregator.go +++ b/pkg/server/aggregator.go @@ -1,6 +1,8 @@ package server import ( + "slices" + "github.com/go-acme/lego/v4/challenge/tlsalpn01" "github.com/traefik/traefik/v2/pkg/config/dynamic" "github.com/traefik/traefik/v2/pkg/log" @@ -91,7 +93,7 @@ func mergeConfiguration(configurations dynamic.Configurations, defaultEntryPoint if configuration.TLS != nil { for _, cert := range configuration.TLS.Certificates { - if containsACMETLS1(cert.Stores) && pvd != "tlsalpn.acme" { + if slices.Contains(cert.Stores, tlsalpn01.ACMETLS1Protocol) && pvd != "tlsalpn.acme" { continue } @@ -179,13 +181,3 @@ func applyModel(cfg dynamic.Configuration) dynamic.Configuration { return cfg } - -func containsACMETLS1(stores []string) bool { - for _, store := range stores { - if store == tlsalpn01.ACMETLS1Protocol { - return true - } - } - - return false -} diff --git a/pkg/server/configurationwatcher_test.go b/pkg/server/configurationwatcher_test.go index 7cf68b881..cc909c81d 100644 --- a/pkg/server/configurationwatcher_test.go +++ b/pkg/server/configurationwatcher_test.go @@ -305,7 +305,7 @@ func TestListenProvidersThrottleProviderConfigReload(t *testing.T) { throttleDuration: 30 * time.Millisecond, } - for i := 0; i < 5; i++ { + for i := range 5 { pvd.messages = append(pvd.messages, dynamic.Message{ ProviderName: "mock", Configuration: &dynamic.Configuration{ diff --git a/pkg/server/middleware/middlewares.go b/pkg/server/middleware/middlewares.go index 073843472..05a4229d3 100644 --- a/pkg/server/middleware/middlewares.go +++ b/pkg/server/middleware/middlewares.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" "reflect" + "slices" "strings" "github.com/containous/alice" @@ -97,7 +98,7 @@ func checkRecursion(ctx context.Context, middlewareName string) (context.Context if !ok { currentStack = []string{} } - if inSlice(middlewareName, currentStack) { + if slices.Contains(currentStack, middlewareName) { return ctx, fmt.Errorf("could not instantiate middleware %s: recursion detected in %s", middlewareName, strings.Join(append(currentStack, middlewareName), "->")) } return context.WithValue(ctx, middlewareStackKey, append(currentStack, middlewareName)), nil @@ -381,12 +382,3 @@ func (b *Builder) buildConstructor(ctx context.Context, middlewareName string) ( return tracing.Wrap(ctx, middleware), nil } - -func inSlice(element string, stack []string) bool { - for _, value := range stack { - if value == element { - return true - } - } - return false -} diff --git a/pkg/server/middleware/tcp/middlewares.go b/pkg/server/middleware/tcp/middlewares.go index 5599a956c..98a3167aa 100644 --- a/pkg/server/middleware/tcp/middlewares.go +++ b/pkg/server/middleware/tcp/middlewares.go @@ -3,6 +3,7 @@ package tcpmiddleware import ( "context" "fmt" + "slices" "strings" "github.com/traefik/traefik/v2/pkg/config/runtime" @@ -74,7 +75,7 @@ func checkRecursion(ctx context.Context, middlewareName string) (context.Context currentStack = []string{} } - if inSlice(middlewareName, currentStack) { + if slices.Contains(currentStack, middlewareName) { return ctx, fmt.Errorf("could not instantiate middleware %s: recursion detected in %s", middlewareName, strings.Join(append(currentStack, middlewareName), "->")) } @@ -117,12 +118,3 @@ func (b *Builder) buildConstructor(ctx context.Context, middlewareName string) ( return middleware, nil } - -func inSlice(element string, stack []string) bool { - for _, value := range stack { - if value == element { - return true - } - } - return false -} diff --git a/pkg/server/router/router_test.go b/pkg/server/router/router_test.go index 0ba85b527..65d074039 100644 --- a/pkg/server/router/router_test.go +++ b/pkg/server/router/router_test.go @@ -945,7 +945,7 @@ func BenchmarkRouterServe(b *testing.B) { reqHost := requestdecorator.New(nil) b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { reqHost.ServeHTTP(w, req, handlers["web"].ServeHTTP) } } @@ -980,7 +980,7 @@ func BenchmarkService(b *testing.B) { handler, _ := serviceManager.BuildHTTP(context.Background(), "foo-service") b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { handler.ServeHTTP(w, req) } } diff --git a/pkg/server/server_entrypoint_tcp_test.go b/pkg/server/server_entrypoint_tcp_test.go index 9d66c44e0..f0b12c8dd 100644 --- a/pkg/server/server_entrypoint_tcp_test.go +++ b/pkg/server/server_entrypoint_tcp_test.go @@ -112,7 +112,7 @@ func testShutdown(t *testing.T, router *tcprouter.Router) { // but technically also as early as the Shutdown has closed the listener, // i.e. during the shutdown and before the gracetime is over. var testOk bool - for i := 0; i < 10; i++ { + for range 10 { loopConn, err := net.Dial("tcp", epAddr) if err == nil { loopConn.Close() @@ -141,7 +141,7 @@ func startEntrypoint(entryPoint *TCPEntryPoint, router *tcprouter.Router) (net.C entryPoint.SwitchRouter(router) - for i := 0; i < 10; i++ { + for range 10 { conn, err := net.Dial("tcp", entryPoint.listener.Addr().String()) if err != nil { time.Sleep(100 * time.Millisecond) diff --git a/pkg/server/service/loadbalancer/mirror/mirror_test.go b/pkg/server/service/loadbalancer/mirror/mirror_test.go index 430baac8f..b417fa13d 100644 --- a/pkg/server/service/loadbalancer/mirror/mirror_test.go +++ b/pkg/server/service/loadbalancer/mirror/mirror_test.go @@ -32,7 +32,7 @@ func TestMirroringOn100(t *testing.T) { }), 50) assert.NoError(t, err) - for i := 0; i < 100; i++ { + for range 100 { mirror.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest(http.MethodGet, "/", nil)) } @@ -61,7 +61,7 @@ func TestMirroringOn10(t *testing.T) { }), 50) assert.NoError(t, err) - for i := 0; i < 10; i++ { + for range 10 { mirror.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest(http.MethodGet, "/", nil)) } @@ -156,7 +156,7 @@ func TestMirroringWithBody(t *testing.T) { mirror := New(handler, pool, defaultMaxBodySize, nil) - for i := 0; i < numMirrors; i++ { + for range numMirrors { err := mirror.AddMirror(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { assert.NotNil(t, r.Body) bb, err := io.ReadAll(r.Body) diff --git a/pkg/server/service/loadbalancer/wrr/wrr_test.go b/pkg/server/service/loadbalancer/wrr/wrr_test.go index 7328fd98d..32068504e 100644 --- a/pkg/server/service/loadbalancer/wrr/wrr_test.go +++ b/pkg/server/service/loadbalancer/wrr/wrr_test.go @@ -40,7 +40,7 @@ func TestBalancer(t *testing.T) { }), Int(1)) recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} - for i := 0; i < 4; i++ { + for range 4 { balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil)) } @@ -68,7 +68,7 @@ func TestBalancerOneServerZeroWeight(t *testing.T) { balancer.AddService("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}), Int(0)) recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} - for i := 0; i < 3; i++ { + for range 3 { balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil)) } @@ -113,7 +113,7 @@ func TestBalancerOneServerDown(t *testing.T) { balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", false) recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} - for i := 0; i < 3; i++ { + for range 3 { balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil)) } @@ -135,14 +135,14 @@ func TestBalancerDownThenUp(t *testing.T) { balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", false) recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} - for i := 0; i < 3; i++ { + for range 3 { balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil)) } assert.Equal(t, 3, recorder.save["first"]) balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", true) recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} - for i := 0; i < 2; i++ { + for range 2 { balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil)) } assert.Equal(t, 1, recorder.save["first"]) @@ -184,7 +184,7 @@ func TestBalancerPropagate(t *testing.T) { }) recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} - for i := 0; i < 8; i++ { + for range 8 { topBalancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil)) } assert.Equal(t, 2, recorder.save["first"]) @@ -197,7 +197,7 @@ func TestBalancerPropagate(t *testing.T) { // fourth gets downed, but balancer2 still up since third is still up. balancer2.SetStatus(context.WithValue(context.Background(), serviceName, "top"), "fourth", false) recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} - for i := 0; i < 8; i++ { + for range 8 { topBalancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil)) } assert.Equal(t, 2, recorder.save["first"]) @@ -211,7 +211,7 @@ func TestBalancerPropagate(t *testing.T) { // down as well for topBalancer. balancer2.SetStatus(context.WithValue(context.Background(), serviceName, "top"), "third", false) recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} - for i := 0; i < 8; i++ { + for range 8 { topBalancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil)) } assert.Equal(t, 4, recorder.save["first"]) @@ -252,7 +252,7 @@ func TestSticky(t *testing.T) { recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} req := httptest.NewRequest(http.MethodGet, "/", nil) - for i := 0; i < 3; i++ { + for range 3 { for _, cookie := range recorder.Result().Cookies() { assert.NotContains(t, "test=first", cookie.Value) assert.NotContains(t, "test=second", cookie.Value) @@ -286,7 +286,7 @@ func TestSticky_FallBack(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "/", nil) req.AddCookie(&http.Cookie{Name: "test", Value: "second"}) - for i := 0; i < 3; i++ { + for range 3 { recorder.ResponseRecorder = httptest.NewRecorder() balancer.ServeHTTP(recorder, req) @@ -313,7 +313,7 @@ func TestBalancerBias(t *testing.T) { recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}} - for i := 0; i < 14; i++ { + for range 14 { balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil)) } diff --git a/pkg/server/service/proxy_test.go b/pkg/server/service/proxy_test.go index 3a0a34553..567ba6105 100644 --- a/pkg/server/service/proxy_test.go +++ b/pkg/server/service/proxy_test.go @@ -31,7 +31,7 @@ func BenchmarkProxy(b *testing.B) { handler, _ := buildProxy(Bool(false), nil, &staticTransport{res}, pool) b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { handler.ServeHTTP(w, req) } } diff --git a/pkg/server/service/roundtripper.go b/pkg/server/service/roundtripper.go index 31493bbb9..fc5f9e88b 100644 --- a/pkg/server/service/roundtripper.go +++ b/pkg/server/service/roundtripper.go @@ -9,6 +9,7 @@ import ( "net" "net/http" "reflect" + "slices" "strings" "sync" "time" @@ -210,12 +211,9 @@ func (k *KerberosRoundTripper) RoundTrip(request *http.Request) (*http.Response, } func containsNTLMorNegotiate(h []string) bool { - for _, s := range h { - if strings.HasPrefix(s, "NTLM") || strings.HasPrefix(s, "Negotiate") { - return true - } - } - return false + return slices.ContainsFunc(h, func(s string) bool { + return strings.HasPrefix(s, "NTLM") || strings.HasPrefix(s, "Negotiate") + }) } func createRootCACertPool(rootCAs []traefiktls.FileOrContent) *x509.CertPool { diff --git a/pkg/server/service/roundtripper_test.go b/pkg/server/service/roundtripper_test.go index 460bc9a60..d9212ab8d 100644 --- a/pkg/server/service/roundtripper_test.go +++ b/pkg/server/service/roundtripper_test.go @@ -139,7 +139,7 @@ func TestKeepConnectionWhenSameConfiguration(t *testing.T) { }, } - for i := 0; i < 10; i++ { + for range 10 { rtManager.Update(dynamicConf) tr, err := rtManager.Get("test") diff --git a/pkg/server/service/service.go b/pkg/server/service/service.go index 39dacd5ad..cc43e76a2 100644 --- a/pkg/server/service/service.go +++ b/pkg/server/service/service.go @@ -85,7 +85,7 @@ func (m *Manager) BuildHTTP(rootCtx context.Context, serviceName string) (http.H value := reflect.ValueOf(*conf.Service) var count int - for i := 0; i < value.NumField(); i++ { + for i := range value.NumField() { if !value.Field(i).IsNil() { count++ } diff --git a/pkg/tcp/wrr_load_balancer_test.go b/pkg/tcp/wrr_load_balancer_test.go index a07f51762..5ee18caad 100644 --- a/pkg/tcp/wrr_load_balancer_test.go +++ b/pkg/tcp/wrr_load_balancer_test.go @@ -135,7 +135,7 @@ func TestLoadBalancing(t *testing.T) { } conn := &fakeConn{writeCall: make(map[string]int)} - for i := 0; i < test.totalCall; i++ { + for range test.totalCall { balancer.ServeTCP(conn) } diff --git a/pkg/tls/tlsmanager.go b/pkg/tls/tlsmanager.go index fb2be8efe..3208ad7d3 100644 --- a/pkg/tls/tlsmanager.go +++ b/pkg/tls/tlsmanager.go @@ -6,6 +6,7 @@ import ( "crypto/x509" "errors" "fmt" + "slices" "strings" "sync" @@ -181,7 +182,7 @@ func (m *Manager) Get(storeName, configName string) (*tls.Config, error) { tlsConfig.GetCertificate = func(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) { domainToCheck := types.CanonicalDomain(clientHello.ServerName) - if isACMETLS(clientHello) { + if slices.Contains(clientHello.SupportedProtos, tlsalpn01.ACMETLS1Protocol) { certificate := acmeTLSStore.GetBestCertificate(clientHello) if certificate == nil { log.WithoutContext().Debugf("TLS: no certificate for TLSALPN challenge: %s", domainToCheck) @@ -419,13 +420,3 @@ func buildDefaultCertificate(defaultCertificate *Certificate) (*tls.Certificate, } return &cert, nil } - -func isACMETLS(clientHello *tls.ClientHelloInfo) bool { - for _, proto := range clientHello.SupportedProtos { - if proto == tlsalpn01.ACMETLS1Protocol { - return true - } - } - - return false -} diff --git a/pkg/types/http_code_range.go b/pkg/types/http_code_range.go index 4a8f541a5..b00ac1957 100644 --- a/pkg/types/http_code_range.go +++ b/pkg/types/http_code_range.go @@ -1,6 +1,7 @@ package types import ( + "slices" "strconv" "strings" ) @@ -34,10 +35,7 @@ func NewHTTPCodeRanges(strBlocks []string) (HTTPCodeRanges, error) { // Contains tests whether the passed status code is within one of its HTTP code ranges. func (h HTTPCodeRanges) Contains(statusCode int) bool { - for _, block := range h { - if statusCode >= block[0] && statusCode <= block[1] { - return true - } - } - return false + return slices.ContainsFunc(h, func(block [2]int) bool { + return statusCode >= block[0] && statusCode <= block[1] + }) } diff --git a/pkg/udp/conn_test.go b/pkg/udp/conn_test.go index 44e748474..651d70064 100644 --- a/pkg/udp/conn_test.go +++ b/pkg/udp/conn_test.go @@ -210,7 +210,7 @@ func testTimeout(t *testing.T, withRead bool) { } }() - for i := 0; i < 10; i++ { + for range 10 { udpConn2, err := net.Dial("udp", ln.Addr().String()) require.NoError(t, err) From 8b759ab797ddafbf45222331e81001f6d46736a1 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Mon, 19 Feb 2024 16:02:04 +0100 Subject: [PATCH 08/19] fix: int overflow during doc generation on 32 bit arch --- pkg/collector/hydratation/hydration.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/collector/hydratation/hydration.go b/pkg/collector/hydratation/hydration.go index 40736f046..c45cfcfbb 100644 --- a/pkg/collector/hydratation/hydration.go +++ b/pkg/collector/hydratation/hydration.go @@ -56,7 +56,7 @@ func fill(field reflect.Value) error { case reflect.Int64: switch field.Type() { case reflect.TypeOf(types.Duration(time.Second)): - setTyped(field, int64(defaultNumber*int(time.Second))) + setTyped(field, types.Duration(defaultNumber*time.Second)) default: setTyped(field, int64(defaultNumber)) } @@ -98,7 +98,7 @@ func setMap(field reflect.Value) error { key := reflect.ValueOf(fmt.Sprintf("%s%d", baseKeyName, i)) // generate value - ptrType := reflect.PtrTo(field.Type().Elem()) + ptrType := reflect.PointerTo(field.Type().Elem()) ptrValue := reflect.New(ptrType) if err := fill(ptrValue); err != nil { return err From 453e21c7c939dead7c5b48eda147490e43021aaa Mon Sep 17 00:00:00 2001 From: Baptiste Mayelle Date: Mon, 19 Feb 2024 16:50:05 +0100 Subject: [PATCH 09/19] fix: add ipallowlist in dashboard --- .../components/_commons/PanelMiddlewares.vue | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/webui/src/components/_commons/PanelMiddlewares.vue b/webui/src/components/_commons/PanelMiddlewares.vue index eccfa5346..ab80b4fd0 100644 --- a/webui/src/components/_commons/PanelMiddlewares.vue +++ b/webui/src/components/_commons/PanelMiddlewares.vue @@ -689,6 +689,54 @@ + + +
+
+
Source Range
+ + {{ range }} + +
+
+
+ + +
+
+
IP Strategy
+
+
+ Depth : + + {{ exData(middleware).ipStrategy.depth }} + +
+
+
+ + Excluded IPs: + + + {{ excludedIPs }} + +
+
+
+
+
From 153765f99fa9b6bafad57bb1c8e159ad9a94b2f5 Mon Sep 17 00:00:00 2001 From: Kevin Pollet Date: Mon, 26 Feb 2024 10:02:06 +0100 Subject: [PATCH 10/19] Allow to configure TLSStore default generated certificate with labels --- .../dynamic-configuration/docker-labels.yml | 6 + .../marathon-labels.json | 6 + pkg/config/dynamic/config.go | 4 +- pkg/config/label/label.go | 4 +- pkg/config/label/label_test.go | 35 +++ pkg/provider/configuration.go | 56 +++- pkg/provider/consulcatalog/config_test.go | 222 ++++++++++++++++ pkg/provider/docker/config_test.go | 243 ++++++++++++++++++ pkg/provider/ecs/config_test.go | 222 ++++++++++++++++ pkg/provider/marathon/config_test.go | 231 +++++++++++++++-- pkg/provider/nomad/config_test.go | 202 +++++++++++++++ pkg/provider/rancher/config_test.go | 132 ++++++++++ pkg/tls/tls.go | 2 +- 13 files changed, 1322 insertions(+), 43 deletions(-) diff --git a/docs/content/reference/dynamic-configuration/docker-labels.yml b/docs/content/reference/dynamic-configuration/docker-labels.yml index 300c4febe..02ac9eb1f 100644 --- a/docs/content/reference/dynamic-configuration/docker-labels.yml +++ b/docs/content/reference/dynamic-configuration/docker-labels.yml @@ -209,6 +209,12 @@ - "traefik.tcp.services.tcpservice01.loadbalancer.proxyprotocol.version=42" - "traefik.tcp.services.tcpservice01.loadbalancer.terminationdelay=42" - "traefik.tcp.services.tcpservice01.loadbalancer.server.port=foobar" +- "traefik.tls.stores.store0.defaultgeneratedcert.domain.main=foobar" +- "traefik.tls.stores.store0.defaultgeneratedcert.domain.sans=foobar, foobar" +- "traefik.tls.stores.store0.defaultgeneratedcert.resolver=foobar" +- "traefik.tls.stores.store1.defaultgeneratedcert.domain.main=foobar" +- "traefik.tls.stores.store1.defaultgeneratedcert.domain.sans=foobar, foobar" +- "traefik.tls.stores.store1.defaultgeneratedcert.resolver=foobar" - "traefik.udp.routers.udprouter0.entrypoints=foobar, foobar" - "traefik.udp.routers.udprouter0.service=foobar" - "traefik.udp.routers.udprouter1.entrypoints=foobar, foobar" diff --git a/docs/content/reference/dynamic-configuration/marathon-labels.json b/docs/content/reference/dynamic-configuration/marathon-labels.json index 55ea30b35..41fa198bd 100644 --- a/docs/content/reference/dynamic-configuration/marathon-labels.json +++ b/docs/content/reference/dynamic-configuration/marathon-labels.json @@ -209,6 +209,12 @@ "traefik.tcp.services.tcpservice01.loadbalancer.proxyprotocol.version": "42", "traefik.tcp.services.tcpservice01.loadbalancer.terminationdelay": "42", "traefik.tcp.services.tcpservice01.loadbalancer.server.port": "foobar", +"traefik.tls.stores.store0.defaultgeneratedcert.domain.main": "foobar", +"traefik.tls.stores.store0.defaultgeneratedcert.domain.sans": "foobar, foobar", +"traefik.tls.stores.store0.defaultgeneratedcert.resolver": "foobar", +"traefik.tls.stores.store1.defaultgeneratedcert.domain.main": "foobar", +"traefik.tls.stores.store1.defaultgeneratedcert.domain.sans": "foobar, foobar", +"traefik.tls.stores.store1.defaultgeneratedcert.resolver": "foobar", "traefik.udp.routers.udprouter0.entrypoints": "foobar, foobar", "traefik.udp.routers.udprouter0.service": "foobar", "traefik.udp.routers.udprouter1.entrypoints": "foobar, foobar", diff --git a/pkg/config/dynamic/config.go b/pkg/config/dynamic/config.go index 469c04acc..eb061c953 100644 --- a/pkg/config/dynamic/config.go +++ b/pkg/config/dynamic/config.go @@ -24,7 +24,7 @@ type Configuration struct { HTTP *HTTPConfiguration `json:"http,omitempty" toml:"http,omitempty" yaml:"http,omitempty" export:"true"` TCP *TCPConfiguration `json:"tcp,omitempty" toml:"tcp,omitempty" yaml:"tcp,omitempty" export:"true"` UDP *UDPConfiguration `json:"udp,omitempty" toml:"udp,omitempty" yaml:"udp,omitempty" export:"true"` - TLS *TLSConfiguration `json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" label:"-" export:"true"` + TLS *TLSConfiguration `json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" export:"true"` } // +k8s:deepcopy-gen=true @@ -32,6 +32,6 @@ type Configuration struct { // TLSConfiguration contains all the configuration parameters of a TLS connection. type TLSConfiguration struct { Certificates []*tls.CertAndStores `json:"certificates,omitempty" toml:"certificates,omitempty" yaml:"certificates,omitempty" label:"-" export:"true"` - Options map[string]tls.Options `json:"options,omitempty" toml:"options,omitempty" yaml:"options,omitempty" export:"true"` + Options map[string]tls.Options `json:"options,omitempty" toml:"options,omitempty" yaml:"options,omitempty" label:"-" export:"true"` Stores map[string]tls.Store `json:"stores,omitempty" toml:"stores,omitempty" yaml:"stores,omitempty" export:"true"` } diff --git a/pkg/config/label/label.go b/pkg/config/label/label.go index 1791f735f..0222f9a14 100644 --- a/pkg/config/label/label.go +++ b/pkg/config/label/label.go @@ -12,9 +12,11 @@ func DecodeConfiguration(labels map[string]string) (*dynamic.Configuration, erro HTTP: &dynamic.HTTPConfiguration{}, TCP: &dynamic.TCPConfiguration{}, UDP: &dynamic.UDPConfiguration{}, + TLS: &dynamic.TLSConfiguration{}, } - err := parser.Decode(labels, conf, parser.DefaultRootName, "traefik.http", "traefik.tcp", "traefik.udp") + // When decoding the TLS configuration we are making sure that only the default TLS store can be configured. + err := parser.Decode(labels, conf, parser.DefaultRootName, "traefik.http", "traefik.tcp", "traefik.udp", "traefik.tls.stores.default") if err != nil { return nil, err } diff --git a/pkg/config/label/label_test.go b/pkg/config/label/label_test.go index 04bce464e..a11fb3976 100644 --- a/pkg/config/label/label_test.go +++ b/pkg/config/label/label_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v2/pkg/config/dynamic" + "github.com/traefik/traefik/v2/pkg/tls" "github.com/traefik/traefik/v2/pkg/types" ) @@ -205,6 +206,10 @@ func TestDecodeConfiguration(t *testing.T) { "traefik.udp.routers.Router1.service": "foobar", "traefik.udp.services.Service0.loadbalancer.server.Port": "42", "traefik.udp.services.Service1.loadbalancer.server.Port": "42", + + "traefik.tls.stores.default.defaultgeneratedcert.resolver": "foobar", + "traefik.tls.stores.default.defaultgeneratedcert.domain.main": "foobar", + "traefik.tls.stores.default.defaultgeneratedcert.domain.sans": "foobar, fiibar", } configuration, err := DecodeConfiguration(labels) @@ -698,6 +703,19 @@ func TestDecodeConfiguration(t *testing.T) { }, }, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{ + "default": { + DefaultGeneratedCert: &tls.GeneratedCert{ + Resolver: "foobar", + Domain: &types.Domain{ + Main: "foobar", + SANs: []string{"foobar", "fiibar"}, + }, + }, + }, + }, + }, } assert.Nil(t, configuration.HTTP.ServersTransports) @@ -1187,6 +1205,19 @@ func TestEncodeConfiguration(t *testing.T) { }, }, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{ + "default": { + DefaultGeneratedCert: &tls.GeneratedCert{ + Resolver: "foobar", + Domain: &types.Domain{ + Main: "foobar", + SANs: []string{"foobar", "fiibar"}, + }, + }, + }, + }, + }, } labels, err := EncodeConfiguration(configuration) @@ -1375,6 +1406,10 @@ func TestEncodeConfiguration(t *testing.T) { "traefik.TCP.Services.Service1.LoadBalancer.server.Port": "42", "traefik.TCP.Services.Service1.LoadBalancer.TerminationDelay": "42", + "traefik.TLS.Stores.default.DefaultGeneratedCert.Resolver": "foobar", + "traefik.TLS.Stores.default.DefaultGeneratedCert.Domain.Main": "foobar", + "traefik.TLS.Stores.default.DefaultGeneratedCert.Domain.SANs": "foobar, fiibar", + "traefik.UDP.Routers.Router0.EntryPoints": "foobar, fiibar", "traefik.UDP.Routers.Router0.Service": "foobar", "traefik.UDP.Routers.Router1.EntryPoints": "foobar, fiibar", diff --git a/pkg/provider/configuration.go b/pkg/provider/configuration.go index 261d68156..ac1e4b54a 100644 --- a/pkg/provider/configuration.go +++ b/pkg/provider/configuration.go @@ -12,9 +12,10 @@ import ( "github.com/Masterminds/sprig/v3" "github.com/traefik/traefik/v2/pkg/config/dynamic" "github.com/traefik/traefik/v2/pkg/log" + "github.com/traefik/traefik/v2/pkg/tls" ) -// Merge Merges multiple configurations. +// Merge merges multiple configurations. func Merge(ctx context.Context, configurations map[string]*dynamic.Configuration) *dynamic.Configuration { logger := log.FromContext(ctx) @@ -34,6 +35,9 @@ func Merge(ctx context.Context, configurations map[string]*dynamic.Configuration Routers: make(map[string]*dynamic.UDPRouter), Services: make(map[string]*dynamic.UDPService), }, + TLS: &dynamic.TLSConfiguration{ + Stores: make(map[string]tls.Store), + }, } servicesToDelete := map[string]struct{}{} @@ -63,6 +67,9 @@ func Merge(ctx context.Context, configurations map[string]*dynamic.Configuration transportsToDelete := map[string]struct{}{} transports := map[string][]string{} + storesToDelete := map[string]struct{}{} + stores := map[string][]string{} + var sortedKeys []string for key := range configurations { sortedKeys = append(sortedKeys, key) @@ -133,6 +140,13 @@ func Merge(ctx context.Context, configurations map[string]*dynamic.Configuration middlewaresTCPToDelete[middlewareName] = struct{}{} } } + + for storeName, store := range conf.TLS.Stores { + stores[storeName] = append(stores[storeName], root) + if !AddStore(configuration.TLS, storeName, store) { + storesToDelete[storeName] = struct{}{} + } + } } for serviceName := range servicesToDelete { @@ -189,10 +203,16 @@ func Merge(ctx context.Context, configurations map[string]*dynamic.Configuration delete(configuration.TCP.Middlewares, middlewareName) } + for storeName := range storesToDelete { + logger.WithField("storeName", storeName). + Errorf("TLS store defined multiple times with different configurations in %v", stores[storeName]) + delete(configuration.TLS.Stores, storeName) + } + return configuration } -// AddServiceTCP Adds a service to a configurations. +// AddServiceTCP adds a service to a configurations. func AddServiceTCP(configuration *dynamic.TCPConfiguration, serviceName string, service *dynamic.TCPService) bool { if _, ok := configuration.Services[serviceName]; !ok { configuration.Services[serviceName] = service @@ -217,7 +237,7 @@ func AddServiceTCP(configuration *dynamic.TCPConfiguration, serviceName string, return true } -// AddRouterTCP Adds a router to a configurations. +// AddRouterTCP adds a router to a configurations. func AddRouterTCP(configuration *dynamic.TCPConfiguration, routerName string, router *dynamic.TCPRouter) bool { if _, ok := configuration.Routers[routerName]; !ok { configuration.Routers[routerName] = router @@ -227,7 +247,7 @@ func AddRouterTCP(configuration *dynamic.TCPConfiguration, routerName string, ro return reflect.DeepEqual(configuration.Routers[routerName], router) } -// AddMiddlewareTCP Adds a middleware to a configurations. +// AddMiddlewareTCP adds a middleware to a configurations. func AddMiddlewareTCP(configuration *dynamic.TCPConfiguration, middlewareName string, middleware *dynamic.TCPMiddleware) bool { if _, ok := configuration.Middlewares[middlewareName]; !ok { configuration.Middlewares[middlewareName] = middleware @@ -272,7 +292,7 @@ func AddRouterUDP(configuration *dynamic.UDPConfiguration, routerName string, ro return reflect.DeepEqual(configuration.Routers[routerName], router) } -// AddService Adds a service to a configurations. +// AddService adds a service to a configurations. func AddService(configuration *dynamic.HTTPConfiguration, serviceName string, service *dynamic.Service) bool { if _, ok := configuration.Services[serviceName]; !ok { configuration.Services[serviceName] = service @@ -297,7 +317,7 @@ func AddService(configuration *dynamic.HTTPConfiguration, serviceName string, se return true } -// AddRouter Adds a router to a configurations. +// AddRouter adds a router to a configurations. func AddRouter(configuration *dynamic.HTTPConfiguration, routerName string, router *dynamic.Router) bool { if _, ok := configuration.Routers[routerName]; !ok { configuration.Routers[routerName] = router @@ -307,7 +327,7 @@ func AddRouter(configuration *dynamic.HTTPConfiguration, routerName string, rout return reflect.DeepEqual(configuration.Routers[routerName], router) } -// AddTransport Adds a transport to a configurations. +// AddTransport adds a transport to a configurations. func AddTransport(configuration *dynamic.HTTPConfiguration, transportName string, transport *dynamic.ServersTransport) bool { if _, ok := configuration.ServersTransports[transportName]; !ok { configuration.ServersTransports[transportName] = transport @@ -317,7 +337,7 @@ func AddTransport(configuration *dynamic.HTTPConfiguration, transportName string return reflect.DeepEqual(configuration.ServersTransports[transportName], transport) } -// AddMiddleware Adds a middleware to a configurations. +// AddMiddleware adds a middleware to a configurations. func AddMiddleware(configuration *dynamic.HTTPConfiguration, middlewareName string, middleware *dynamic.Middleware) bool { if _, ok := configuration.Middlewares[middlewareName]; !ok { configuration.Middlewares[middlewareName] = middleware @@ -327,7 +347,17 @@ func AddMiddleware(configuration *dynamic.HTTPConfiguration, middlewareName stri return reflect.DeepEqual(configuration.Middlewares[middlewareName], middleware) } -// MakeDefaultRuleTemplate Creates the default rule template. +// AddStore adds a middleware to a configurations. +func AddStore(configuration *dynamic.TLSConfiguration, storeName string, store tls.Store) bool { + if _, ok := configuration.Stores[storeName]; !ok { + configuration.Stores[storeName] = store + return true + } + + return reflect.DeepEqual(configuration.Stores[storeName], store) +} + +// MakeDefaultRuleTemplate creates the default rule template. func MakeDefaultRuleTemplate(defaultRule string, funcMap template.FuncMap) (*template.Template, error) { defaultFuncMap := sprig.TxtFuncMap() defaultFuncMap["normalize"] = Normalize @@ -339,7 +369,7 @@ func MakeDefaultRuleTemplate(defaultRule string, funcMap template.FuncMap) (*tem return template.New("defaultRule").Funcs(defaultFuncMap).Parse(defaultRule) } -// BuildTCPRouterConfiguration Builds a router configuration. +// BuildTCPRouterConfiguration builds a router configuration. func BuildTCPRouterConfiguration(ctx context.Context, configuration *dynamic.TCPConfiguration) { for routerName, router := range configuration.Routers { loggerRouter := log.FromContext(ctx).WithField(log.RouterName, routerName) @@ -364,7 +394,7 @@ func BuildTCPRouterConfiguration(ctx context.Context, configuration *dynamic.TCP } } -// BuildUDPRouterConfiguration Builds a router configuration. +// BuildUDPRouterConfiguration builds a router configuration. func BuildUDPRouterConfiguration(ctx context.Context, configuration *dynamic.UDPConfiguration) { for routerName, router := range configuration.Routers { loggerRouter := log.FromContext(ctx).WithField(log.RouterName, routerName) @@ -386,7 +416,7 @@ func BuildUDPRouterConfiguration(ctx context.Context, configuration *dynamic.UDP } } -// BuildRouterConfiguration Builds a router configuration. +// BuildRouterConfiguration builds a router configuration. func BuildRouterConfiguration(ctx context.Context, configuration *dynamic.HTTPConfiguration, defaultRouterName string, defaultRuleTpl *template.Template, model interface{}) { if len(configuration.Routers) == 0 { if len(configuration.Services) > 1 { @@ -433,7 +463,7 @@ func BuildRouterConfiguration(ctx context.Context, configuration *dynamic.HTTPCo } } -// Normalize Replace all special chars with `-`. +// Normalize replaces all special chars with `-`. func Normalize(name string) string { fargs := func(c rune) bool { return !unicode.IsLetter(c) && !unicode.IsNumber(c) diff --git a/pkg/provider/consulcatalog/config_test.go b/pkg/provider/consulcatalog/config_test.go index bb6f41846..9039f4697 100644 --- a/pkg/provider/consulcatalog/config_test.go +++ b/pkg/provider/consulcatalog/config_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/traefik/traefik/v2/pkg/config/dynamic" "github.com/traefik/traefik/v2/pkg/tls" + "github.com/traefik/traefik/v2/pkg/types" ) func Int(v int) *int { return &v } @@ -69,6 +70,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -120,6 +124,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -163,6 +170,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -206,6 +216,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -255,6 +268,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, } @@ -341,6 +357,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -411,6 +430,9 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -498,6 +520,9 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -570,6 +595,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -630,6 +658,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -687,6 +718,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -747,6 +781,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -796,6 +833,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -846,6 +886,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -894,6 +937,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -943,6 +989,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -998,6 +1047,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1045,6 +1097,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1103,6 +1158,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1165,6 +1223,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1220,6 +1281,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1287,6 +1351,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1348,6 +1415,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1425,6 +1495,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1482,6 +1555,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1553,6 +1629,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1616,6 +1695,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1665,6 +1747,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1715,6 +1800,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1769,6 +1857,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1799,6 +1890,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1830,6 +1924,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1861,6 +1958,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1892,6 +1992,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1925,6 +2028,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1975,6 +2081,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2035,6 +2144,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2092,6 +2204,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2142,6 +2257,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2189,6 +2307,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2232,6 +2353,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2285,6 +2409,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2333,6 +2460,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2421,6 +2551,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2505,6 +2638,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2548,6 +2684,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2590,6 +2729,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2634,6 +2776,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2733,6 +2878,9 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2809,6 +2957,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2883,6 +3034,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2934,6 +3088,74 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, + }, + }, + { + desc: "one container with default generated certificate labels", + items: []itemData{ + { + ID: "Test", + Node: "Node1", + Name: "dev/Test", + Labels: map[string]string{ + "traefik.tls.stores.default.defaultgeneratedcert.resolver": "foobar", + "traefik.tls.stores.default.defaultgeneratedcert.domain.main": "foobar", + "traefik.tls.stores.default.defaultgeneratedcert.domain.sans": "foobar, fiibar", + }, + Address: "127.0.0.1", + Port: "80", + Status: api.HealthPassing, + }, + }, + expected: &dynamic.Configuration{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{}, + Middlewares: map[string]*dynamic.TCPMiddleware{}, + Services: map[string]*dynamic.TCPService{}, + }, + UDP: &dynamic.UDPConfiguration{ + Routers: map[string]*dynamic.UDPRouter{}, + Services: map[string]*dynamic.UDPService{}, + }, + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ + "dev-Test": { + Service: "dev-Test", + Rule: "Host(`dev-Test.traefik.wtf`)", + DefaultRule: true, + }, + }, + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ + "dev-Test": { + LoadBalancer: &dynamic.ServersLoadBalancer{ + Servers: []dynamic.Server{ + { + URL: "http://127.0.0.1:80", + }, + }, + PassHostHeader: Bool(true), + }, + }, + }, + ServersTransports: map[string]*dynamic.ServersTransport{}, + }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{ + "default": { + DefaultGeneratedCert: &tls.GeneratedCert{ + Resolver: "foobar", + Domain: &types.Domain{ + Main: "foobar", + SANs: []string{"foobar", "fiibar"}, + }, + }, + }, + }, + }, }, }, } diff --git a/pkg/provider/docker/config_test.go b/pkg/provider/docker/config_test.go index a8fd786e1..0b835c6c4 100644 --- a/pkg/provider/docker/config_test.go +++ b/pkg/provider/docker/config_test.go @@ -11,6 +11,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/traefik/traefik/v2/pkg/config/dynamic" + "github.com/traefik/traefik/v2/pkg/tls" + "github.com/traefik/traefik/v2/pkg/types" ) func TestDefaultRule(t *testing.T) { @@ -74,6 +76,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -130,6 +135,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -188,6 +196,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -238,6 +249,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -288,6 +302,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -344,6 +361,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, } @@ -421,6 +441,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -461,6 +484,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -501,6 +527,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -556,6 +585,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -642,6 +674,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -718,6 +753,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -775,6 +813,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -833,6 +874,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -889,6 +933,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -946,6 +993,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1009,6 +1059,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1066,6 +1119,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1132,6 +1188,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1217,6 +1276,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1297,6 +1359,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1360,6 +1425,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1446,6 +1514,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1526,6 +1597,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1628,6 +1702,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1702,6 +1779,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1798,6 +1878,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1877,6 +1960,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1956,6 +2042,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2013,6 +2102,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2071,6 +2163,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2133,6 +2228,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2169,6 +2267,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2207,6 +2308,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2247,6 +2351,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2274,6 +2381,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2314,6 +2424,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2344,6 +2457,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2386,6 +2502,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2416,6 +2535,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2455,6 +2577,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2496,6 +2621,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2554,6 +2682,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2622,6 +2753,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2687,6 +2821,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2745,6 +2882,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2800,6 +2940,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2851,6 +2994,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2912,6 +3058,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2968,6 +3117,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -3069,6 +3221,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -3119,6 +3274,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -3171,6 +3329,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -3236,6 +3397,88 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, + }, + }, + { + desc: "one container with default generated certificate labels", + containers: []dockerData{ + { + ServiceName: "Test", + Name: "Test", + Labels: map[string]string{ + "traefik.tls.stores.default.defaultgeneratedcert.resolver": "foobar", + "traefik.tls.stores.default.defaultgeneratedcert.domain.main": "foobar", + "traefik.tls.stores.default.defaultgeneratedcert.domain.sans": "foobar, fiibar", + }, + NetworkSettings: networkSettings{ + Ports: nat.PortMap{ + nat.Port("79/tcp"): []nat.PortBinding{{ + HostIP: "192.168.0.1", + HostPort: "8080", + }}, + nat.Port("80/tcp"): []nat.PortBinding{{ + HostIP: "192.168.0.1", + HostPort: "8081", + }}, + }, + Networks: map[string]*networkData{ + "bridge": { + Name: "bridge", + Addr: "127.0.0.1", + }, + }, + }, + }, + }, + expected: &dynamic.Configuration{ + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ + "Test": { + Service: "Test", + Rule: "Host(`Test.traefik.wtf`)", + DefaultRule: true, + }, + }, + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ + "Test": { + LoadBalancer: &dynamic.ServersLoadBalancer{ + Servers: []dynamic.Server{ + { + URL: "http://127.0.0.1:79", + }, + }, + PassHostHeader: Bool(true), + }, + }, + }, + ServersTransports: map[string]*dynamic.ServersTransport{}, + }, + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{}, + Middlewares: map[string]*dynamic.TCPMiddleware{}, + Services: map[string]*dynamic.TCPService{}, + }, + UDP: &dynamic.UDPConfiguration{ + Routers: map[string]*dynamic.UDPRouter{}, + Services: map[string]*dynamic.UDPService{}, + }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{ + "default": { + DefaultGeneratedCert: &tls.GeneratedCert{ + Resolver: "foobar", + Domain: &types.Domain{ + Main: "foobar", + SANs: []string{"foobar", "fiibar"}, + }, + }, + }, + }, + }, }, }, } diff --git a/pkg/provider/ecs/config_test.go b/pkg/provider/ecs/config_test.go index e6a190213..f00506094 100644 --- a/pkg/provider/ecs/config_test.go +++ b/pkg/provider/ecs/config_test.go @@ -8,6 +8,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/traefik/traefik/v2/pkg/config/dynamic" + "github.com/traefik/traefik/v2/pkg/tls" + "github.com/traefik/traefik/v2/pkg/types" ) func Int(v int) *int { return &v } @@ -70,6 +72,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -121,6 +126,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -174,6 +182,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -219,6 +230,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -264,6 +278,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -315,6 +332,9 @@ func TestDefaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, } @@ -386,6 +406,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -421,6 +444,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -456,6 +482,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -506,6 +535,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -582,6 +614,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -648,6 +683,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -700,6 +738,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -753,6 +794,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -804,6 +848,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -856,6 +903,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -914,6 +964,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -966,6 +1019,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1022,6 +1078,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1092,6 +1151,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1162,6 +1224,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1220,6 +1285,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1296,6 +1364,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1366,6 +1437,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1453,6 +1527,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1517,6 +1594,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1598,6 +1678,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1668,6 +1751,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1737,6 +1823,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1789,6 +1878,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1842,6 +1934,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1895,6 +1990,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1966,6 +2064,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2023,6 +2124,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2054,6 +2158,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2087,6 +2194,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2122,6 +2232,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2158,6 +2271,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2193,6 +2309,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2229,6 +2348,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2282,6 +2404,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2345,6 +2470,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2405,6 +2533,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2458,6 +2589,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2508,6 +2642,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2554,6 +2691,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2610,6 +2750,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2661,6 +2804,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2752,6 +2898,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2797,6 +2946,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2844,6 +2996,76 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, + }, + }, + { + desc: "one container with default generated certificate", + containers: []ecsInstance{ + instance( + name("Test"), + labels(map[string]string{ + "traefik.tls.stores.default.defaultgeneratedcert.resolver": "foobar", + "traefik.tls.stores.default.defaultgeneratedcert.domain.main": "foobar", + "traefik.tls.stores.default.defaultgeneratedcert.domain.sans": "foobar, fiibar", + }), + iMachine( + mState(ec2.InstanceStateNameRunning), + mPrivateIP("127.0.0.1"), + mPorts( + mPort(0, 80, "tcp"), + ), + ), + ), + }, + expected: &dynamic.Configuration{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{}, + Middlewares: map[string]*dynamic.TCPMiddleware{}, + Services: map[string]*dynamic.TCPService{}, + }, + UDP: &dynamic.UDPConfiguration{ + Routers: map[string]*dynamic.UDPRouter{}, + Services: map[string]*dynamic.UDPService{}, + }, + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ + "Test": { + Service: "Test", + Rule: "Host(`Test.traefik.wtf`)", + DefaultRule: true, + }, + }, + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ + "Test": { + LoadBalancer: &dynamic.ServersLoadBalancer{ + Servers: []dynamic.Server{ + { + URL: "http://127.0.0.1:80", + }, + }, + PassHostHeader: Bool(true), + }, + }, + }, + ServersTransports: map[string]*dynamic.ServersTransport{}, + }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{ + "default": { + DefaultGeneratedCert: &tls.GeneratedCert{ + Resolver: "foobar", + Domain: &types.Domain{ + Main: "foobar", + SANs: []string{"foobar", "fiibar"}, + }, + }, + }, + }, + }, }, }, } diff --git a/pkg/provider/marathon/config_test.go b/pkg/provider/marathon/config_test.go index 8bab4768e..6e78830c5 100644 --- a/pkg/provider/marathon/config_test.go +++ b/pkg/provider/marathon/config_test.go @@ -9,6 +9,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/traefik/traefik/v2/pkg/config/dynamic" + "github.com/traefik/traefik/v2/pkg/tls" + "github.com/traefik/traefik/v2/pkg/types" ) func Int(v int) *int { return &v } @@ -76,6 +78,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -102,6 +107,9 @@ func TestBuildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -143,6 +151,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -196,6 +207,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -249,6 +263,9 @@ func TestBuildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -302,6 +319,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -363,6 +383,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -421,6 +444,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -467,6 +493,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -509,6 +538,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -554,6 +586,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -597,6 +632,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -641,6 +679,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -691,6 +732,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -735,6 +779,9 @@ func TestBuildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -806,6 +853,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -871,6 +921,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -925,6 +978,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -976,6 +1032,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1030,6 +1089,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1074,6 +1136,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1119,6 +1184,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1168,6 +1236,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1194,6 +1265,9 @@ func TestBuildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1221,32 +1295,8 @@ func TestBuildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, - }, - }, - { - desc: "one app with traefik.enable=false", - applications: withApplications( - application( - appID("/app"), - appPorts(80, 81), - withTasks(localhostTask()), - withLabel("traefik.enable", "false"), - )), - expected: &dynamic.Configuration{ - TCP: &dynamic.TCPConfiguration{ - Routers: map[string]*dynamic.TCPRouter{}, - Middlewares: map[string]*dynamic.TCPMiddleware{}, - Services: map[string]*dynamic.TCPService{}, - }, - UDP: &dynamic.UDPConfiguration{ - Routers: map[string]*dynamic.UDPRouter{}, - Services: map[string]*dynamic.UDPService{}, - }, - HTTP: &dynamic.HTTPConfiguration{ - Routers: map[string]*dynamic.Router{}, - Middlewares: map[string]*dynamic.Middleware{}, - Services: map[string]*dynamic.Service{}, - ServersTransports: map[string]*dynamic.ServersTransport{}, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, }, }, }, @@ -1275,6 +1325,39 @@ func TestBuildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, + }, + }, + { + desc: "one app with traefik.enable=false", + applications: withApplications( + application( + appID("/app"), + appPorts(80, 81), + withTasks(localhostTask()), + withLabel("traefik.enable", "false"), + )), + expected: &dynamic.Configuration{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{}, + Middlewares: map[string]*dynamic.TCPMiddleware{}, + Services: map[string]*dynamic.TCPService{}, + }, + UDP: &dynamic.UDPConfiguration{ + Routers: map[string]*dynamic.UDPRouter{}, + Services: map[string]*dynamic.UDPService{}, + }, + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{}, + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{}, + ServersTransports: map[string]*dynamic.ServersTransport{}, + }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1303,6 +1386,9 @@ func TestBuildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1331,6 +1417,9 @@ func TestBuildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1376,6 +1465,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1421,6 +1513,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1465,6 +1560,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1510,6 +1608,9 @@ func TestBuildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1552,6 +1653,9 @@ func TestBuildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1590,6 +1694,9 @@ func TestBuildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1636,6 +1743,9 @@ func TestBuildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1679,6 +1789,9 @@ func TestBuildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1726,6 +1839,9 @@ func TestBuildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1790,6 +1906,9 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1851,6 +1970,66 @@ func TestBuildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, + }, + }, + { + desc: "simple application with default generated certificate labels", + applications: withApplications( + application( + appID("/app"), + appPorts(80), + withTasks(localhostTask(taskPorts(80))), + withLabel("traefik.tls.stores.default.defaultgeneratedcert.resolver", "foobar"), + withLabel("traefik.tls.stores.default.defaultgeneratedcert.domain.main", "foobar"), + withLabel("traefik.tls.stores.default.defaultgeneratedcert.domain.sans", "foobar, fiibar"), + )), + expected: &dynamic.Configuration{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{}, + Middlewares: map[string]*dynamic.TCPMiddleware{}, + Services: map[string]*dynamic.TCPService{}, + }, + UDP: &dynamic.UDPConfiguration{ + Routers: map[string]*dynamic.UDPRouter{}, + Services: map[string]*dynamic.UDPService{}, + }, + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ + "app": { + Service: "app", + Rule: "Host(`app.marathon.localhost`)", + DefaultRule: true, + }, + }, + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ + "app": {LoadBalancer: &dynamic.ServersLoadBalancer{ + Servers: []dynamic.Server{ + { + URL: "http://localhost:80", + }, + }, + PassHostHeader: Bool(true), + }}, + }, + ServersTransports: map[string]*dynamic.ServersTransport{}, + }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{ + "default": { + DefaultGeneratedCert: &tls.GeneratedCert{ + Resolver: "foobar", + Domain: &types.Domain{ + Main: "foobar", + SANs: []string{"foobar", "fiibar"}, + }, + }, + }, + }, + }, }, }, } diff --git a/pkg/provider/nomad/config_test.go b/pkg/provider/nomad/config_test.go index c4047f924..9c964586b 100644 --- a/pkg/provider/nomad/config_test.go +++ b/pkg/provider/nomad/config_test.go @@ -7,6 +7,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/traefik/traefik/v2/pkg/config/dynamic" + "github.com/traefik/traefik/v2/pkg/tls" + "github.com/traefik/traefik/v2/pkg/types" ) func Test_defaultRule(t *testing.T) { @@ -62,6 +64,9 @@ func Test_defaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -113,6 +118,9 @@ func Test_defaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -155,6 +163,9 @@ func Test_defaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -203,6 +214,9 @@ func Test_defaultRule(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, } @@ -274,6 +288,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -344,6 +361,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -404,6 +424,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -461,6 +484,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -521,6 +547,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -570,6 +599,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -620,6 +652,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -668,6 +703,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -717,6 +755,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -772,6 +813,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -820,6 +864,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -878,6 +925,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -940,6 +990,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -995,6 +1048,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1063,6 +1119,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1125,6 +1184,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1181,6 +1243,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1242,6 +1307,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1291,6 +1359,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1341,6 +1412,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1395,6 +1469,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1425,6 +1502,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1456,6 +1536,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1488,6 +1571,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1521,6 +1607,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1571,6 +1660,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1631,6 +1723,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1688,6 +1783,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1738,6 +1836,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1785,6 +1886,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1828,6 +1932,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1881,6 +1988,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1929,6 +2039,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2017,6 +2130,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2101,6 +2217,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2144,6 +2263,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2186,6 +2308,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2230,6 +2355,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2311,6 +2439,9 @@ func Test_buildConfig(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2389,6 +2520,9 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -2465,6 +2599,74 @@ func Test_buildConfig(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, + }, + }, + { + desc: "one service with default generated certificate tags", + items: []item{ + { + ID: "id", + Node: "Node1", + Name: "dev/Test", + Address: "127.0.0.1", + Port: 9999, + ExtraConf: configuration{Enable: true}, + Tags: []string{ + "traefik.tls.stores.default.defaultgeneratedcert.resolver = foobar", + "traefik.tls.stores.default.defaultgeneratedcert.domain.main = foobar", + "traefik.tls.stores.default.defaultgeneratedcert.domain.sans = foobar, fiibar", + }, + }, + }, + expected: &dynamic.Configuration{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{}, + Middlewares: map[string]*dynamic.TCPMiddleware{}, + Services: map[string]*dynamic.TCPService{}, + }, + UDP: &dynamic.UDPConfiguration{ + Routers: map[string]*dynamic.UDPRouter{}, + Services: map[string]*dynamic.UDPService{}, + }, + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ + "dev-Test": { + Service: "dev-Test", + Rule: "Host(`dev-Test.traefik.test`)", + DefaultRule: true, + }, + }, + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ + "dev-Test": { + LoadBalancer: &dynamic.ServersLoadBalancer{ + Servers: []dynamic.Server{ + { + URL: "http://127.0.0.1:9999", + }, + }, + PassHostHeader: Bool(true), + }, + }, + }, + ServersTransports: map[string]*dynamic.ServersTransport{}, + }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{ + "default": { + DefaultGeneratedCert: &tls.GeneratedCert{ + Resolver: "foobar", + Domain: &types.Domain{ + Main: "foobar", + SANs: []string{"foobar", "fiibar"}, + }, + }, + }, + }, + }, }, }, } diff --git a/pkg/provider/rancher/config_test.go b/pkg/provider/rancher/config_test.go index 0db7b955b..dbed070c9 100644 --- a/pkg/provider/rancher/config_test.go +++ b/pkg/provider/rancher/config_test.go @@ -7,6 +7,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/traefik/traefik/v2/pkg/config/dynamic" + "github.com/traefik/traefik/v2/pkg/tls" + "github.com/traefik/traefik/v2/pkg/types" ) func Int(v int) *int { return &v } @@ -64,6 +66,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -134,6 +139,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -207,6 +215,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -257,6 +268,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -286,6 +300,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -315,6 +332,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -363,6 +383,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -396,6 +419,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -446,6 +472,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -506,6 +535,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -563,6 +595,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -612,6 +647,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -662,6 +700,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -709,6 +750,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -752,6 +796,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -801,6 +848,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -849,6 +899,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -924,6 +977,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -996,6 +1052,9 @@ func Test_buildConfiguration(t *testing.T) { }, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1039,6 +1098,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1081,6 +1143,9 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, }, }, { @@ -1125,6 +1190,73 @@ func Test_buildConfiguration(t *testing.T) { Services: map[string]*dynamic.Service{}, ServersTransports: map[string]*dynamic.ServersTransport{}, }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{}, + }, + }, + }, + { + desc: "one service with default generated certificate labels", + containers: []rancherData{ + { + Name: "Test", + Labels: map[string]string{ + "traefik.tls.stores.default.defaultgeneratedcert.resolver": "foobar", + "traefik.tls.stores.default.defaultgeneratedcert.domain.main": "foobar", + "traefik.tls.stores.default.defaultgeneratedcert.domain.sans": "foobar, fiibar", + }, + Port: "80/tcp", + Containers: []string{"127.0.0.1"}, + Health: "", + State: "", + }, + }, + expected: &dynamic.Configuration{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{}, + Middlewares: map[string]*dynamic.TCPMiddleware{}, + Services: map[string]*dynamic.TCPService{}, + }, + UDP: &dynamic.UDPConfiguration{ + Routers: map[string]*dynamic.UDPRouter{}, + Services: map[string]*dynamic.UDPService{}, + }, + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ + "Test": { + Service: "Test", + Rule: "Host(`Test.traefik.wtf`)", + DefaultRule: true, + }, + }, + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ + "Test": { + LoadBalancer: &dynamic.ServersLoadBalancer{ + Servers: []dynamic.Server{ + { + URL: "http://127.0.0.1:80", + }, + }, + PassHostHeader: Bool(true), + }, + }, + }, + ServersTransports: map[string]*dynamic.ServersTransport{}, + }, + TLS: &dynamic.TLSConfiguration{ + Stores: map[string]tls.Store{ + "default": { + DefaultGeneratedCert: &tls.GeneratedCert{ + Resolver: "foobar", + Domain: &types.Domain{ + Main: "foobar", + SANs: []string{"foobar", "fiibar"}, + }, + }, + }, + }, + }, }, }, } diff --git a/pkg/tls/tls.go b/pkg/tls/tls.go index 85bbeada1..bacc3e337 100644 --- a/pkg/tls/tls.go +++ b/pkg/tls/tls.go @@ -38,7 +38,7 @@ func (o *Options) SetDefaults() { // Store holds the options for a given Store. type Store struct { - DefaultCertificate *Certificate `json:"defaultCertificate,omitempty" toml:"defaultCertificate,omitempty" yaml:"defaultCertificate,omitempty" export:"true"` + DefaultCertificate *Certificate `json:"defaultCertificate,omitempty" toml:"defaultCertificate,omitempty" yaml:"defaultCertificate,omitempty" label:"-" export:"true"` DefaultGeneratedCert *GeneratedCert `json:"defaultGeneratedCert,omitempty" toml:"defaultGeneratedCert,omitempty" yaml:"defaultGeneratedCert,omitempty" export:"true"` } From f7edb394f2f6e44e0c3ba3c00be03a35085e4bcd Mon Sep 17 00:00:00 2001 From: Andi Sardina Ramos Date: Mon, 26 Feb 2024 16:02:04 +0200 Subject: [PATCH 11/19] chore(webui): Migrate to Quasar 2.x and Vue.js 3.x --- webui/.eslintignore | 6 + webui/{.eslintrc.js => .eslintrc.cjs} | 33 +- webui/{.postcssrc.js => .postcssrc.cjs} | 0 webui/babel.config.cjs | 16 + webui/babel.config.js | 5 - webui/{src/index.template.html => index.html} | 3 +- webui/jsconfig.json | 39 + webui/package.json | 65 +- webui/postcss.config.cjs | 27 + webui/quasar.conf.js | 50 +- webui/src/App.vue | 10 +- webui/src/_directives/resize.js | 20 +- webui/src/_helpers/Errors.js | 2 +- webui/src/_helpers/Helps.js | 17 +- webui/src/_helpers/Mutations.js | 9 +- webui/src/_middleware/Boot.js | 14 +- webui/src/_mixins/GetTableProps.js | 12 +- webui/src/_mixins/Pagination.js | 6 +- webui/src/boot/_globals.js | 4 +- webui/src/boot/_init.js | 8 +- webui/src/boot/api.js | 14 +- webui/src/components/_commons/AvatarState.vue | 30 +- .../src/components/_commons/BooleanState.vue | 32 +- webui/src/components/_commons/Chips.vue | 9 +- webui/src/components/_commons/MainTable.vue | 85 +- webui/src/components/_commons/NavBar.vue | 151 +- webui/src/components/_commons/PageDefault.vue | 2 +- .../components/_commons/PanelHealthCheck.vue | 105 +- .../components/_commons/PanelMiddlewares.vue | 903 +- .../_commons/PanelMirroringServices.vue | 51 +- .../_commons/PanelRouterDetails.vue | 128 +- .../src/components/_commons/PanelServers.vue | 101 +- .../_commons/PanelServiceDetails.vue | 112 +- webui/src/components/_commons/PanelTLS.vue | 97 +- .../_commons/PanelWeightedServices.vue | 49 +- .../src/components/_commons/ProviderIcon.vue | 16 +- webui/src/components/_commons/SidePanel.vue | 23 +- webui/src/components/_commons/SkeletonBox.vue | 6 +- .../_commons/StickyServiceDetails.vue | 75 +- webui/src/components/_commons/TLSState.vue | 15 +- webui/src/components/_commons/ToolBar.vue | 72 +- .../src/components/_commons/ToolBarTable.vue | 48 +- webui/src/components/dashboard/PanelChart.vue | 102 +- webui/src/components/dashboard/PanelEntry.vue | 28 +- .../src/components/dashboard/PanelFeature.vue | 15 +- .../components/dashboard/PanelProvider.vue | 23 +- ...r.variables.styl => quasar.variables.scss} | 18 +- webui/src/layouts/Default.vue | 4 +- webui/src/pages/_commons/Error404.vue | 12 +- webui/src/pages/_commons/MiddlewareDetail.vue | 110 +- webui/src/pages/_commons/RouterDetail.vue | 248 +- webui/src/pages/_commons/ServiceDetail.vue | 191 +- webui/src/pages/dashboard/Index.vue | 316 +- webui/src/pages/http/Middlewares.vue | 54 +- webui/src/pages/http/Routers.vue | 54 +- webui/src/pages/http/Services.vue | 54 +- webui/src/pages/tcp/Middlewares.vue | 54 +- webui/src/pages/tcp/Routers.vue | 54 +- webui/src/pages/tcp/Services.vue | 49 +- webui/src/pages/udp/Routers.vue | 53 +- webui/src/pages/udp/Services.vue | 54 +- webui/src/router/index.js | 28 +- webui/src/router/routes.js | 6 +- webui/src/store/index.js | 12 +- webui/yarn.lock | 8364 ++++------------- 65 files changed, 4374 insertions(+), 7999 deletions(-) rename webui/{.eslintrc.js => .eslintrc.cjs} (62%) rename webui/{.postcssrc.js => .postcssrc.cjs} (100%) create mode 100644 webui/babel.config.cjs delete mode 100644 webui/babel.config.js rename webui/{src/index.template.html => index.html} (94%) create mode 100644 webui/jsconfig.json create mode 100644 webui/postcss.config.cjs rename webui/src/css/{quasar.variables.styl => quasar.variables.scss} (63%) diff --git a/webui/.eslintignore b/webui/.eslintignore index 9b1c8b133..9f81cf845 100644 --- a/webui/.eslintignore +++ b/webui/.eslintignore @@ -1 +1,7 @@ /dist +/src-capacitor +/src-cordova +/.quasar +/node_modules +.eslintrc.cjs +/quasar.config.*.temporary.compiled* diff --git a/webui/.eslintrc.js b/webui/.eslintrc.cjs similarity index 62% rename from webui/.eslintrc.js rename to webui/.eslintrc.cjs index f8fee91f8..c08b11557 100644 --- a/webui/.eslintrc.js +++ b/webui/.eslintrc.cjs @@ -2,21 +2,24 @@ module.exports = { root: true, parserOptions: { - parser: 'babel-eslint', - sourceType: 'module' + parser: '@babel/eslint-parser', + ecmaVersion: 2021, // Allows for the parsing of modern ECMAScript features }, env: { + node: true, browser: true, - mocha: true + mocha: true, + 'vue/setup-compiler-macros': true }, extends: [ // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules. - 'plugin:vue/essential', - '@vue/standard', - 'plugin:mocha/recommended' + 'plugin:vue/vue3-essential', + 'plugin:vue/vue3-recommended', + 'plugin:mocha/recommended', + 'standard' ], // required to lint *.vue files @@ -26,10 +29,16 @@ module.exports = { ], globals: { - 'ga': true, // Google Analytics - 'cordova': true, - '__statics': true, - 'process': true + ga: 'readonly', // Google Analytics + cordova: 'readonly', + __statics: 'readonly', + __QUASAR_SSR__: 'readonly', + __QUASAR_SSR_SERVER__: 'readonly', + __QUASAR_SSR_CLIENT__: 'readonly', + __QUASAR_SSR_PWA__: 'readonly', + process: 'readonly', + Capacitor: 'readonly', + chrome: 'readonly' }, // add your custom rules here @@ -39,6 +48,8 @@ module.exports = { // allow paren-less arrow functions 'arrow-parens': 'off', 'one-var': 'off', + 'no-void': 'off', + 'multiline-ternary': 'off', 'import/first': 'off', 'import/named': 'error', @@ -49,6 +60,7 @@ module.exports = { 'import/no-unresolved': 'off', 'import/no-extraneous-dependencies': 'off', 'prefer-promise-reject-errors': 'off', + 'vue/multi-word-component-names': 'off', // allow console.log during development only //'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', @@ -56,3 +68,4 @@ module.exports = { //'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off' } } + diff --git a/webui/.postcssrc.js b/webui/.postcssrc.cjs similarity index 100% rename from webui/.postcssrc.js rename to webui/.postcssrc.cjs diff --git a/webui/babel.config.cjs b/webui/babel.config.cjs new file mode 100644 index 000000000..cd63d3933 --- /dev/null +++ b/webui/babel.config.cjs @@ -0,0 +1,16 @@ +/* eslint-disable */ + +module.exports = api => { + return { + presets: [ + [ + '@quasar/babel-preset-app', + api.caller(caller => caller && caller.target === 'node') + ? { targets: { node: 'current' } } + : {} + ] + ] + } +} + + diff --git a/webui/babel.config.js b/webui/babel.config.js deleted file mode 100644 index 9408c6cd4..000000000 --- a/webui/babel.config.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - presets: [ - '@quasar/babel-preset-app' - ] -} diff --git a/webui/src/index.template.html b/webui/index.html similarity index 94% rename from webui/src/index.template.html rename to webui/index.html index 70fee7d64..6eb6d6091 100644 --- a/webui/src/index.template.html +++ b/webui/index.html @@ -20,7 +20,6 @@ - -
+ diff --git a/webui/jsconfig.json b/webui/jsconfig.json new file mode 100644 index 000000000..456944a5e --- /dev/null +++ b/webui/jsconfig.json @@ -0,0 +1,39 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "src/*": [ + "src/*" + ], + "app/*": [ + "*" + ], + "components/*": [ + "src/components/*" + ], + "layouts/*": [ + "src/layouts/*" + ], + "pages/*": [ + "src/pages/*" + ], + "assets/*": [ + "src/assets/*" + ], + "boot/*": [ + "src/boot/*" + ], + "stores/*": [ + "src/stores/*" + ], + "vue$": [ + "node_modules/vue/dist/vue.runtime.esm-bundler.js" + ] + } + }, + "exclude": [ + "dist", + ".quasar", + "node_modules" + ] +} \ No newline at end of file diff --git a/webui/package.json b/webui/package.json index aa11f65b7..aa8090eae 100644 --- a/webui/package.json +++ b/webui/package.json @@ -16,42 +16,45 @@ "build:nc": "yarn build" }, "dependencies": { - "@quasar/extras": "^1.11.2", - "axios": "^0.21.1", - "bowser": "^2.5.2", - "chart.js": "^2.8.0", - "dot-prop": "^5.2.0", + "@quasar/extras": "^1.16.9", + "axios": "^1.6.7", + "bowser": "^2.11.0", + "chart.js": "^4.4.1", "core-js": "^3.35.1", - "iframe-resizer": "^4.2.11", + "dot-prop": "^8.0.2", + "iframe-resizer": "^4.3.9", "lodash.isequal": "4.5.0", - "moment": "^2.24.0", - "quasar": "^1.22.10", - "query-string": "^6.13.1", + "moment": "^2.30.1", + "quasar": "^2.14.3", + "query-string": "^8.1.0", "vh-check": "^2.0.5", - "vue-chartjs": "^3.4.2", - "vuex-map-fields": "^1.3.4" + "vue": "^3.0.0", + "vue-chartjs": "^5.3.0", + "vue-router": "^4.0.12", + "vuex": "^4.1.0", + "vuex-map-fields": "^1.4.1" }, "devDependencies": { - "@quasar/app": "^2.4.3", - "@vue/eslint-config-standard": "^4.0.0", - "@vue/test-utils": "^1.0.0-beta.29", - "babel-eslint": "^10.0.1", - "chai": "4.2.0", - "eslint": "^5.10.0", - "eslint-loader": "^2.1.1", - "eslint-plugin-prettier": "3.1.1", - "eslint-plugin-mocha": "6.2.1", - "eslint-plugin-vue": "^5.0.0", - "mocha": "^6.2.2", - "mocha-webpack": "^2.0.0-beta.0", - "prettier": "1.19.1" + "@babel/core": "^7.23.9", + "@babel/eslint-parser": "^7.23.10", + "@quasar/app-vite": "^1.4.3", + "@quasar/babel-preset-app": "^2.0.2", + "@vue/test-utils": "^2.4.4", + "autoprefixer": "^10.4.2", + "chai": "5.0.3", + "eslint": "^8.11.0", + "eslint-config-standard": "^17.0.0", + "eslint-plugin-import": "^2.19.1", + "eslint-plugin-mocha": "^10.2.0", + "eslint-plugin-n": "^16.6.2", + "eslint-plugin-promise": "^6.0.0", + "eslint-plugin-vue": "^9.0.0", + "mocha": "^10.2.0", + "postcss": "^8.4.14" }, "engines": { - "node": ">= 8.9.0", - "npm": ">= 5.6.0", - "yarn": ">= 1.6.0" - }, - "browserslist": [ - "last 1 version, not dead, ie >= 11" - ] + "node": "^20 || ^18 || ^16", + "npm": ">= 6.13.4", + "yarn": ">= 1.21.1" + } } diff --git a/webui/postcss.config.cjs b/webui/postcss.config.cjs new file mode 100644 index 000000000..94b7b1c85 --- /dev/null +++ b/webui/postcss.config.cjs @@ -0,0 +1,27 @@ +/* eslint-disable */ +// https://github.com/michael-ciniawsky/postcss-load-config + +module.exports = { + plugins: [ + // https://github.com/postcss/autoprefixer + require('autoprefixer')({ + overrideBrowserslist: [ + 'last 4 Chrome versions', + 'last 4 Firefox versions', + 'last 4 Edge versions', + 'last 4 Safari versions', + 'last 4 Android versions', + 'last 4 ChromeAndroid versions', + 'last 4 FirefoxAndroid versions', + 'last 4 iOS versions' + ] + }) + + // https://github.com/elchininet/postcss-rtlcss + // If you want to support RTL css, then + // 1. yarn/npm install postcss-rtlcss + // 2. optionally set quasar.config.js > framework > lang to an RTL language + // 3. uncomment the following line: + // require('postcss-rtlcss') + ] +} diff --git a/webui/quasar.conf.js b/webui/quasar.conf.js index 1e7bf08a5..29d00f12a 100644 --- a/webui/quasar.conf.js +++ b/webui/quasar.conf.js @@ -1,12 +1,18 @@ // Configuration for your app // https://quasar.dev/quasar-cli/quasar-conf-js -module.exports = function (ctx) { +const { configure } = require('quasar/wrappers') + +module.exports = configure(function (ctx) { return { + eslint: { + warnings: true, + errors: true + }, + // app boot file (/src/boot) // --> boot files are part of "main.js" boot: [ - '_globals', 'api', '_hacks', '_init' @@ -114,6 +120,17 @@ module.exports = function (ctx) { supportIE: false, build: { + viteVuePluginOptions: { + template: { + compilerOptions: { + isCustomElement: (tag) => tag.startsWith('hub-') + } + } + }, + target: { + browser: ['edge88', 'firefox78', 'chrome87', 'safari13.1'], + node: 'node20' + }, publicPath: process.env.APP_PUBLIC_PATH || '', env: process.env.APP_ENV === 'development' ? { // staging: @@ -131,22 +148,7 @@ module.exports = function (ctx) { } }, scopeHoisting: true, - // vueRouterMode: 'history', - // vueCompiler: true, - // gzip: true, - // analyze: true, - // extractCSS: false, - extendWebpack (cfg) { - cfg.module.rules.push({ - enforce: 'pre', - test: /\.(js|vue)$/, - loader: 'eslint-loader', - exclude: /node_modules/, - options: { - formatter: require('eslint').CLIEngine.getFormatter('stylish') - } - }) - } + vueRouterMode: 'hash' // available values: 'hash', 'history' }, devServer: { @@ -166,16 +168,24 @@ module.exports = function (ctx) { animations: [], ssr: { - pwa: false + pwa: false, }, pwa: { + + workboxMode: 'injectManifest', // or 'generateSW' // workboxPluginMode: 'InjectManifest', // workboxOptions: {}, // only for NON InjectManifest workboxOptions: { skipWaiting: true, clientsClaim: true }, + + chainWebpackCustomSW (chain) { + chain.plugin('eslint-webpack-plugin') + .use(ESLintPlugin, [{ extensions: ['js'] }]) + }, + manifest: { // name: 'Traefik', // short_name: 'Traefik', @@ -247,4 +257,4 @@ module.exports = function (ctx) { } } } -} +}) diff --git a/webui/src/App.vue b/webui/src/App.vue index d655741b1..824ed04e6 100644 --- a/webui/src/App.vue +++ b/webui/src/App.vue @@ -13,6 +13,11 @@ export default { computed: { ...mapGetters('core', { coreVersion: 'version' }) }, + watch: { + '$q.dark.isActive' (val) { + localStorage.setItem('traefik-dark', val) + } + }, beforeCreate () { // Set vue instance APP.vue = () => this.$root @@ -21,11 +26,6 @@ export default { console.log('Quasar -> ', this.$q.version) this.$q.dark.set(localStorage.getItem('traefik-dark') === 'true') - }, - watch: { - '$q.dark.isActive' (val) { - localStorage.setItem('traefik-dark', val) - } } } diff --git a/webui/src/_directives/resize.js b/webui/src/_directives/resize.js index 59411eb2f..3a0500a44 100644 --- a/webui/src/_directives/resize.js +++ b/webui/src/_directives/resize.js @@ -1,8 +1,16 @@ -import Vue from 'vue' -import iFrameResize from 'iframe-resizer/js/iframeResizer' +import iframeResize from 'iframe-resizer/js/iframeResizer' -Vue.directive('resize', { - bind: function (el, { value = {} }) { - el.addEventListener('load', () => iFrameResize(value, el)) +const resize = { + mounted (el, binding) { + const options = binding.value || {} + el.addEventListener('load', () => iframeResize(options, el)) + }, + unmounted (el) { + const resizableEl = el + if (resizableEl.iFrameResizer) { + resizableEl.iFrameResizer.removeListeners() + } } -}) +} + +export default resize diff --git a/webui/src/_helpers/Errors.js b/webui/src/_helpers/Errors.js index 749885076..482766f16 100644 --- a/webui/src/_helpers/Errors.js +++ b/webui/src/_helpers/Errors.js @@ -22,7 +22,7 @@ class Errors { static handleResponse (error) { console.log('handleResponse', error, error.response) - let body = error.response.data + const body = error.response.data if (error.response.status === 401) { // TODO - actions... } diff --git a/webui/src/_helpers/Helps.js b/webui/src/_helpers/Helps.js index b8ba03d9e..96aef3e62 100644 --- a/webui/src/_helpers/Helps.js +++ b/webui/src/_helpers/Helps.js @@ -1,4 +1,4 @@ -import { get } from 'dot-prop' +import { getProperty } from 'dot-prop' class Helps { // Getters @@ -11,7 +11,7 @@ class Helps { // ------------------------------------------------------------------------ static get (obj, prop, def = undefined) { - return get(obj, prop, def) + return getProperty(obj, prop, def) } static hasIn (obj, prop) { @@ -39,13 +39,12 @@ class Helps { } static removeEmptyObjects (objects) { - const obj = {} - Object.entries(objects).map(item => { - if (item[1] !== '') { - obj[item[0]] = item[1] - } - }) - return obj + Object.entries(objects) + .filter(item => item[1] !== '') + .reduce((acc, item) => { + acc[item[0]] = item[1] + return acc + }, {}) } // Helps -> Numbers diff --git a/webui/src/_helpers/Mutations.js b/webui/src/_helpers/Mutations.js index 71faeec30..6550fb696 100644 --- a/webui/src/_helpers/Mutations.js +++ b/webui/src/_helpers/Mutations.js @@ -1,8 +1,8 @@ -import { set, get } from 'dot-prop' +import { setProperty, getProperty } from 'dot-prop' export const withPagination = (type, opts = {}) => (state, data) => { const { isSameContext, statePath } = opts - const currentState = get(state, statePath) + const currentState = getProperty(state, statePath) let newState @@ -13,7 +13,7 @@ export const withPagination = (type, opts = {}) => (state, data) => { loading: true } break - case 'success': + case 'success': { const { body, page } = data newState = { ...currentState, @@ -28,6 +28,7 @@ export const withPagination = (type, opts = {}) => (state, data) => { loading: false } break + } case 'failure': newState = { ...currentState, @@ -39,6 +40,6 @@ export const withPagination = (type, opts = {}) => (state, data) => { } if (newState) { - set(state, statePath, newState) + setProperty(state, statePath, newState) } } diff --git a/webui/src/_middleware/Boot.js b/webui/src/_middleware/Boot.js index 8fc5c968b..378794516 100644 --- a/webui/src/_middleware/Boot.js +++ b/webui/src/_middleware/Boot.js @@ -4,6 +4,11 @@ import Helps from '../_helpers/Helps' const Boot = { install (Vue, options) { Vue.mixin({ + filters: { + capFirstLetter (value) { + return Helps.capFirstLetter(value) + } + }, data () { return { } @@ -28,14 +33,9 @@ const Boot = { } } }, - methods: { - }, - filters: { - capFirstLetter (value) { - return Helps.capFirstLetter(value) - } - }, created () { + }, + methods: { } }) } diff --git a/webui/src/_mixins/GetTableProps.js b/webui/src/_mixins/GetTableProps.js index 020b54657..9c0e08824 100644 --- a/webui/src/_mixins/GetTableProps.js +++ b/webui/src/_mixins/GetTableProps.js @@ -1,9 +1,9 @@ -import { get } from 'dot-prop' +import { getProperty } from 'dot-prop' import { QChip } from 'quasar' -import Chips from '../components/_commons/Chips' -import ProviderIcon from '../components/_commons/ProviderIcon' -import AvatarState from '../components/_commons/AvatarState' -import TLSState from '../components/_commons/TLSState' +import Chips from '../components/_commons/Chips.vue' +import ProviderIcon from '../components/_commons/ProviderIcon.vue' +import AvatarState from '../components/_commons/AvatarState.vue' +import TLSState from '../components/_commons/TLSState.vue' const allColumns = [ { @@ -141,7 +141,7 @@ const GetTablePropsMixin = { path: `/${type.replace('-', '/', 'gi')}/${encodeURIComponent(row.name)}` }), columns: allColumns.filter(c => - get(propsByType, `${type}.columns`, []).includes(c.name) + getProperty(propsByType, `${type}.columns`, []).includes(c.name) ) } } diff --git a/webui/src/_mixins/Pagination.js b/webui/src/_mixins/Pagination.js index 4c2091626..a090beac2 100644 --- a/webui/src/_mixins/Pagination.js +++ b/webui/src/_mixins/Pagination.js @@ -1,4 +1,4 @@ -import { get } from 'dot-prop' +import { getProperty } from 'dot-prop' export default function PaginationMixin (opts = {}) { const { pollingIntervalTime, rowsPerPage = 10 } = opts @@ -28,7 +28,7 @@ export default function PaginationMixin (opts = {}) { currentPage = page currentLimit = limit || rowsPerPage - const fetchMethod = get(this, opts.fetchMethod) + const fetchMethod = getProperty(this, opts.fetchMethod) return fetchMethod({ ...params, @@ -41,7 +41,7 @@ export default function PaginationMixin (opts = {}) { }) }, initFetch (params) { - const scrollerRef = get(this.$refs, opts.scrollerRef) + const scrollerRef = getProperty(this.$refs, opts.scrollerRef) if (scrollerRef) { scrollerRef.stop() diff --git a/webui/src/boot/_globals.js b/webui/src/boot/_globals.js index f23935ca9..f099d03cd 100644 --- a/webui/src/boot/_globals.js +++ b/webui/src/boot/_globals.js @@ -1,8 +1,8 @@ import { APP } from '../_helpers/APP' import Boot from '../_middleware/Boot' -export default async ({ app, router, store, Vue }) => { - Vue.use(Boot) +export default async ({ app, router, store }) => { + app.use(Boot) APP.root = app APP.router = router diff --git a/webui/src/boot/_init.js b/webui/src/boot/_init.js index 9c78853ae..5ec3caf4e 100644 --- a/webui/src/boot/_init.js +++ b/webui/src/boot/_init.js @@ -1,10 +1,14 @@ import { APP } from '../_helpers/APP' import errors from '../_helpers/Errors' +import resize from '../_directives/resize' + +export default async ({ app, router }) => { + // Directives + app.directive('resize', resize) -export default async ({ Vue }) => { // Router // ---------------------------------------------- - APP.router.beforeEach(async (to, from, next) => { + router.beforeEach(async (to, from, next) => { // Set APP APP.routeTo = to APP.routeFrom = from diff --git a/webui/src/boot/api.js b/webui/src/boot/api.js index 706330d8c..8d4f5b314 100644 --- a/webui/src/boot/api.js +++ b/webui/src/boot/api.js @@ -1,12 +1,16 @@ +import { boot } from 'quasar/wrappers' import axios from 'axios' - import { APP } from '../_helpers/APP' // Set config defaults when creating the instance -const API = axios.create({ +const api = axios.create({ baseURL: APP.config.apiUrl }) -export default async ({ app, Vue }) => { - Vue.prototype.$api = app.api = APP.api = API -} +export default boot(({ app }) => { + app.config.globalProperties.$axios = axios + app.config.globalProperties.$api = api + APP.api = api +}) + +export { api } diff --git a/webui/src/components/_commons/AvatarState.vue b/webui/src/components/_commons/AvatarState.vue index a0adcd002..e74e73104 100644 --- a/webui/src/components/_commons/AvatarState.vue +++ b/webui/src/components/_commons/AvatarState.vue @@ -1,16 +1,32 @@