Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display default TLS options in the dashboard #9312

Merged
merged 2 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/api/handler_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/gorilla/mux"
"github.com/traefik/traefik/v2/pkg/config/runtime"
"github.com/traefik/traefik/v2/pkg/log"
"github.com/traefik/traefik/v2/pkg/tls"
)

type routerRepresentation struct {
Expand All @@ -20,6 +21,10 @@ type routerRepresentation struct {
}

func newRouterRepresentation(name string, rt *runtime.RouterInfo) routerRepresentation {
if rt.TLS != nil && rt.TLS.Options == "" {
rt.TLS.Options = tls.DefaultTLSConfigName
}

return routerRepresentation{
RouterInfo: rt,
Name: name,
Expand Down
47 changes: 47 additions & 0 deletions pkg/api/handler_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,52 @@ func TestHandler_HTTP(t *testing.T) {
jsonFile: "testdata/router-bar.json",
},
},
{
desc: "one router by id, implicitly using default TLS options",
path: "/api/http/routers/baz@myprovider",
conf: runtime.Configuration{
Routers: map[string]*runtime.RouterInfo{
"baz@myprovider": {
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.baz`)",
Middlewares: []string{"auth", "addPrefixTest@anotherprovider"},
TLS: &dynamic.RouterTLSConfig{},
},
Status: "enabled",
},
},
},
expected: expected{
statusCode: http.StatusOK,
jsonFile: "testdata/router-baz-default-tls-options.json",
},
},
{
desc: "one router by id, using specific TLS options",
path: "/api/http/routers/baz@myprovider",
conf: runtime.Configuration{
Routers: map[string]*runtime.RouterInfo{
"baz@myprovider": {
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.baz`)",
Middlewares: []string{"auth", "addPrefixTest@anotherprovider"},
TLS: &dynamic.RouterTLSConfig{
Options: "myTLS",
},
},
Status: "enabled",
},
},
},
expected: expected{
statusCode: http.StatusOK,
jsonFile: "testdata/router-baz-custom-tls-options.json",
},
},
{
desc: "one router by id, that does not exist",
path: "/api/http/routers/foo@myprovider",
Expand Down Expand Up @@ -811,6 +857,7 @@ func TestHandler_HTTP(t *testing.T) {
// To lazily initialize the Statuses.
rtConf.PopulateUsedBy()
rtConf.GetRoutersByEntryPoints(context.Background(), []string{"web"}, false)
rtConf.GetRoutersByEntryPoints(context.Background(), []string{"web"}, true)

handler := New(static.Configuration{API: &static.API{}, Global: &static.Global{}}, rtConf)
server := httptest.NewServer(handler.createRouter())
Expand Down
20 changes: 20 additions & 0 deletions pkg/api/testdata/router-baz-custom-tls-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"entryPoints": [
"web"
],
"middlewares": [
"auth",
"addPrefixTest@anotherprovider"
],
"name": "baz@myprovider",
"provider": "myprovider",
"rule": "Host(`foo.baz`)",
"service": "foo-service@myprovider",
"tls": {
"options": "myTLS"
},
"status": "enabled",
"using": [
"web"
]
}
20 changes: 20 additions & 0 deletions pkg/api/testdata/router-baz-default-tls-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"entryPoints": [
"web"
],
"middlewares": [
"auth",
"addPrefixTest@anotherprovider"
],
"name": "baz@myprovider",
"provider": "myprovider",
"rule": "Host(`foo.baz`)",
"service": "foo-service@myprovider",
"tls": {
"options": "default"
},
"status": "enabled",
"using": [
"web"
]
}