Redirection: permanent move option.
This commit is contained in:
parent
c944d203fb
commit
58d6681824
83 changed files with 622 additions and 8611 deletions
|
@ -229,9 +229,12 @@ func getBuffering(container dockerData) *types.Buffering {
|
|||
}
|
||||
|
||||
func getRedirect(container dockerData) *types.Redirect {
|
||||
permanent := label.GetBoolValue(container.Labels, label.TraefikFrontendRedirectPermanent, false)
|
||||
|
||||
if label.Has(container.Labels, label.TraefikFrontendRedirectEntryPoint) {
|
||||
return &types.Redirect{
|
||||
EntryPoint: label.GetStringValue(container.Labels, label.TraefikFrontendRedirectEntryPoint, ""),
|
||||
Permanent: permanent,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,6 +243,7 @@ func getRedirect(container dockerData) *types.Redirect {
|
|||
return &types.Redirect{
|
||||
Regex: label.GetStringValue(container.Labels, label.TraefikFrontendRedirectRegex, ""),
|
||||
Replacement: label.GetStringValue(container.Labels, label.TraefikFrontendRedirectReplacement, ""),
|
||||
Permanent: permanent,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -122,6 +122,7 @@ func TestDockerBuildConfiguration(t *testing.T) {
|
|||
label.TraefikFrontendRedirectEntryPoint: "https",
|
||||
label.TraefikFrontendRedirectRegex: "nope",
|
||||
label.TraefikFrontendRedirectReplacement: "nope",
|
||||
label.TraefikFrontendRedirectPermanent: "true",
|
||||
label.TraefikFrontendRule: "Host:traefik.io",
|
||||
label.TraefikFrontendWhitelistSourceRange: "10.10.10.10",
|
||||
|
||||
|
@ -259,6 +260,7 @@ func TestDockerBuildConfiguration(t *testing.T) {
|
|||
EntryPoint: "https",
|
||||
Regex: "",
|
||||
Replacement: "",
|
||||
Permanent: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1221,6 +1223,20 @@ func TestDockerGetRedirect(t *testing.T) {
|
|||
EntryPoint: "https",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should return a struct when entry point redirect label (permanent)",
|
||||
container: containerJSON(
|
||||
name("test1"),
|
||||
labels(map[string]string{
|
||||
label.TraefikFrontendRedirectEntryPoint: "https",
|
||||
label.TraefikFrontendRedirectPermanent: "true",
|
||||
}),
|
||||
),
|
||||
expected: &types.Redirect{
|
||||
EntryPoint: "https",
|
||||
Permanent: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should return a struct when regex redirect labels",
|
||||
container: containerJSON(
|
||||
|
@ -1235,6 +1251,22 @@ func TestDockerGetRedirect(t *testing.T) {
|
|||
Replacement: "$1",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should return a struct when regex redirect tags (permanent)",
|
||||
container: containerJSON(
|
||||
name("test1"),
|
||||
labels(map[string]string{
|
||||
label.TraefikFrontendRedirectRegex: "(.*)",
|
||||
label.TraefikFrontendRedirectReplacement: "$1",
|
||||
label.TraefikFrontendRedirectPermanent: "true",
|
||||
}),
|
||||
),
|
||||
expected: &types.Redirect{
|
||||
Regex: "(.*)",
|
||||
Replacement: "$1",
|
||||
Permanent: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
|
|
|
@ -100,9 +100,12 @@ func getServicePort(container dockerData, serviceName string) string {
|
|||
func getServiceRedirect(container dockerData, serviceName string) *types.Redirect {
|
||||
serviceLabels := getServiceLabels(container, serviceName)
|
||||
|
||||
permanent := getServiceBoolValue(container, serviceLabels, label.SuffixFrontendRedirectPermanent, false)
|
||||
|
||||
if hasStrictServiceLabel(serviceLabels, label.SuffixFrontendRedirectEntryPoint) {
|
||||
return &types.Redirect{
|
||||
EntryPoint: getStrictServiceStringValue(serviceLabels, label.SuffixFrontendRedirectEntryPoint, label.DefaultFrontendRedirectEntryPoint),
|
||||
Permanent: permanent,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,6 +114,7 @@ func getServiceRedirect(container dockerData, serviceName string) *types.Redirec
|
|||
return &types.Redirect{
|
||||
Regex: getStrictServiceStringValue(serviceLabels, label.SuffixFrontendRedirectRegex, ""),
|
||||
Replacement: getStrictServiceStringValue(serviceLabels, label.SuffixFrontendRedirectReplacement, ""),
|
||||
Permanent: permanent,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ func TestDockerServiceBuildConfiguration(t *testing.T) {
|
|||
label.Prefix + "service." + label.SuffixFrontendRedirectEntryPoint: "https",
|
||||
label.Prefix + "service." + label.SuffixFrontendRedirectRegex: "nope",
|
||||
label.Prefix + "service." + label.SuffixFrontendRedirectReplacement: "nope",
|
||||
label.Prefix + "service." + label.SuffixFrontendRedirectPermanent: "true",
|
||||
label.Prefix + "service." + label.SuffixFrontendWhitelistSourceRange: "10.10.10.10",
|
||||
|
||||
label.Prefix + "service." + label.SuffixFrontendRequestHeaders: "Access-Control-Allow-Methods:POST,GET,OPTIONS || Content-type: application/json; charset=utf-8",
|
||||
|
@ -218,6 +219,7 @@ func TestDockerServiceBuildConfiguration(t *testing.T) {
|
|||
EntryPoint: "https",
|
||||
Regex: "",
|
||||
Replacement: "",
|
||||
Permanent: true,
|
||||
},
|
||||
|
||||
Routes: map[string]types.Route{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue