Redirection: permanent move option.
This commit is contained in:
parent
c944d203fb
commit
58d6681824
83 changed files with 622 additions and 8611 deletions
|
@ -501,16 +501,21 @@ func (p *Provider) getServers(application marathon.Application, serviceName stri
|
|||
func getRedirect(application marathon.Application, serviceName string) *types.Redirect {
|
||||
labels := getLabels(application, serviceName)
|
||||
|
||||
permanent := label.GetBoolValue(labels, getLabelName(serviceName, label.SuffixFrontendRedirectPermanent), false)
|
||||
|
||||
if label.Has(labels, getLabelName(serviceName, label.SuffixFrontendRedirectEntryPoint)) {
|
||||
return &types.Redirect{
|
||||
EntryPoint: label.GetStringValue(labels, getLabelName(serviceName, label.SuffixFrontendRedirectEntryPoint), ""),
|
||||
Permanent: permanent,
|
||||
}
|
||||
}
|
||||
|
||||
if label.Has(labels, getLabelName(serviceName, label.SuffixFrontendRedirectRegex)) &&
|
||||
label.Has(labels, getLabelName(serviceName, label.SuffixFrontendRedirectReplacement)) {
|
||||
return &types.Redirect{
|
||||
Regex: label.GetStringValue(labels, getLabelName(serviceName, label.SuffixFrontendRedirectRegex), ""),
|
||||
Replacement: label.GetStringValue(labels, getLabelName(serviceName, label.SuffixFrontendRedirectReplacement), ""),
|
||||
Permanent: permanent,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -204,6 +204,7 @@ func TestBuildConfigurationNonAPIErrors(t *testing.T) {
|
|||
withLabel(label.TraefikFrontendRedirectEntryPoint, "https"),
|
||||
withLabel(label.TraefikFrontendRedirectRegex, "nope"),
|
||||
withLabel(label.TraefikFrontendRedirectReplacement, "nope"),
|
||||
withLabel(label.TraefikFrontendRedirectPermanent, "true"),
|
||||
withLabel(label.TraefikFrontendRule, "Host:traefik.io"),
|
||||
withLabel(label.TraefikFrontendWhitelistSourceRange, "10.10.10.10"),
|
||||
|
||||
|
@ -342,6 +343,7 @@ func TestBuildConfigurationNonAPIErrors(t *testing.T) {
|
|||
},
|
||||
Redirect: &types.Redirect{
|
||||
EntryPoint: "https",
|
||||
Permanent: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -524,6 +526,7 @@ func TestBuildConfigurationServicesNonAPIErrors(t *testing.T) {
|
|||
withServiceLabel(label.TraefikFrontendRedirectEntryPoint, "https", "containous"),
|
||||
withServiceLabel(label.TraefikFrontendRedirectRegex, "nope", "containous"),
|
||||
withServiceLabel(label.TraefikFrontendRedirectReplacement, "nope", "containous"),
|
||||
withServiceLabel(label.TraefikFrontendRedirectPermanent, "true", "containous"),
|
||||
withServiceLabel(label.TraefikFrontendRule, "Host:traefik.io", "containous"),
|
||||
withServiceLabel(label.TraefikFrontendWhitelistSourceRange, "10.10.10.10", "containous"),
|
||||
|
||||
|
@ -661,6 +664,7 @@ func TestBuildConfigurationServicesNonAPIErrors(t *testing.T) {
|
|||
},
|
||||
Redirect: &types.Redirect{
|
||||
EntryPoint: "https",
|
||||
Permanent: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1698,6 +1702,18 @@ func TestGetRedirect(t *testing.T) {
|
|||
EntryPoint: "https",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should return a struct when entry point redirect label (permanent)",
|
||||
application: application(
|
||||
appPorts(80),
|
||||
withLabel(label.TraefikFrontendRedirectEntryPoint, "https"),
|
||||
withLabel(label.TraefikFrontendRedirectPermanent, "true"),
|
||||
),
|
||||
expected: &types.Redirect{
|
||||
EntryPoint: "https",
|
||||
Permanent: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should return a struct when regex redirect labels",
|
||||
application: application(
|
||||
|
@ -1748,6 +1764,21 @@ func TestGetRedirect(t *testing.T) {
|
|||
Replacement: "$1",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should return a struct when regex redirect labels on service (permanent)",
|
||||
application: application(
|
||||
appPorts(80),
|
||||
withLabel(label.Prefix+"containous."+label.SuffixFrontendRedirectRegex, "(.*)"),
|
||||
withLabel(label.Prefix+"containous."+label.SuffixFrontendRedirectReplacement, "$1"),
|
||||
withLabel(label.Prefix+"containous."+label.SuffixFrontendRedirectPermanent, "true"),
|
||||
),
|
||||
serviceName: "containous",
|
||||
expected: &types.Redirect{
|
||||
Regex: "(.*)",
|
||||
Replacement: "$1",
|
||||
Permanent: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue