Revert "use-regex annotation should be applied to only one Location"

This reverts commit a8a8b5f6e9.
This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-07-15 11:20:47 -04:00 committed by GitHub
parent 51a661d666
commit dc3876666b
4 changed files with 55 additions and 11 deletions

View file

@ -171,6 +171,7 @@ var (
"buildOpentracing": buildOpentracing,
"proxySetHeader": proxySetHeader,
"buildInfluxDB": buildInfluxDB,
"enforceRegexModifier": enforceRegexModifier,
"buildCustomErrorDeps": buildCustomErrorDeps,
"buildCustomErrorLocationsPerServer": buildCustomErrorLocationsPerServer,
"shouldLoadModSecurityModule": shouldLoadModSecurityModule,
@ -372,9 +373,26 @@ func needsRewrite(location *ingress.Location) bool {
return false
}
// enforceRegexModifier checks if the "rewrite-target" or "use-regex" annotation
// is used on any location path within a server
func enforceRegexModifier(input interface{}) bool {
locations, ok := input.([]*ingress.Location)
if !ok {
klog.Errorf("expected an '[]*ingress.Location' type but %T was returned", input)
return false
}
for _, location := range locations {
if needsRewrite(location) || location.Rewrite.UseRegex {
return true
}
}
return false
}
// buildLocation produces the location string, if the ingress has redirects
// (specified through the nginx.ingress.kubernetes.io/rewrite-target annotation)
func buildLocation(input interface{}) string {
func buildLocation(input interface{}, enforceRegex bool) string {
location, ok := input.(*ingress.Location)
if !ok {
klog.Errorf("expected an '*ingress.Location' type but %T was returned", input)
@ -382,7 +400,7 @@ func buildLocation(input interface{}) string {
}
path := location.Path
if location.Rewrite.UseRegex {
if enforceRegex {
return fmt.Sprintf(`~* "^%s"`, path)
}