1
0
Fork 0

redirect to another entryPoint per frontend

This commit is contained in:
Manuel Zapf 2017-11-18 13:50:03 +01:00 committed by Traefiker
parent 66e489addb
commit 5d6384e101
19 changed files with 251 additions and 14 deletions

View file

@ -76,6 +76,13 @@ func (p *Provider) getBasicAuth(service rancherData) []string {
return []string{}
}
func (p *Provider) getRedirect(service rancherData) string {
if redirect, err := getServiceLabel(service, types.LabelFrontendRedirect); err == nil {
return redirect
}
return ""
}
func (p *Provider) getFrontendName(service rancherData) string {
// Replace '.' with '-' in quoted keys because of this issue https://github.com/BurntSushi/toml/issues/78
return provider.Normalize(p.getFrontendRule(service))
@ -239,6 +246,7 @@ func (p *Provider) loadRancherConfig(services []rancherData) *types.Configuratio
"getSticky": p.getSticky,
"hasStickinessLabel": p.hasStickinessLabel,
"getStickinessCookieName": p.getStickinessCookieName,
"getRedirect": p.getRedirect,
}
// filter services
@ -270,6 +278,7 @@ func (p *Provider) loadRancherConfig(services []rancherData) *types.Configuratio
if err != nil {
log.Error(err)
}
return configuration
}

View file

@ -489,6 +489,35 @@ func TestRancherGetPassHostHeader(t *testing.T) {
}
}
func TestRancherGetRedirect(t *testing.T) {
provider := &Provider{
Domain: "rancher.localhost",
}
testCases := []struct {
service rancherData
expected string
}{
{
service: rancherData{
Name: "test-service",
Labels: map[string]string{
types.LabelFrontendRedirect: "https",
},
},
expected: "https",
},
}
for _, test := range testCases {
actual := provider.getRedirect(test.service)
if actual != test.expected {
t.Fatalf("got %q, expected %q", actual, test.expected)
}
}
}
func TestRancherGetLabel(t *testing.T) {
services := []struct {
service rancherData
@ -544,6 +573,7 @@ func TestRancherLoadRancherConfig(t *testing.T) {
Labels: map[string]string{
types.LabelPort: "80",
types.LabelFrontendAuthBasic: "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
types.LabelFrontendRedirect: "https",
},
Health: "healthy",
Containers: []string{"127.0.0.1"},
@ -556,6 +586,7 @@ func TestRancherLoadRancherConfig(t *testing.T) {
EntryPoints: []string{},
BasicAuth: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"},
Priority: 0,
Redirect: "https",
Routes: map[string]types.Route{
"route-frontend-Host-test-service-rancher-localhost": {