Skip to content

Commit

Permalink
MEDIUM: config: #489 allow multiple rewrites in single annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
dosmanak authored and ivanmatmati committed Oct 21, 2022
1 parent df3d1df commit effdda4
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions pkg/annotations/ingress/reqPathRewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,29 @@ func (a *ReqPathRewrite) GetName() string {
}

func (a *ReqPathRewrite) Process(k store.K8s, annotations ...map[string]string) (err error) {
input := common.GetValue(a.GetName(), annotations...)
input := strings.TrimSpace(common.GetValue(a.GetName(), annotations...))
if input == "" {
return
}
parts := strings.Fields(strings.TrimSpace(input))
for _, rule := range strings.Split(input, "\n") {
parts := strings.Fields(strings.TrimSpace(rule))

var rewrite *rules.ReqPathRewrite
switch len(parts) {
case 1:
rewrite = &rules.ReqPathRewrite{
PathMatch: "(.*)",
PathFmt: parts[0],
var rewrite *rules.ReqPathRewrite
switch len(parts) {
case 1:
rewrite = &rules.ReqPathRewrite{
PathMatch: "(.*)",
PathFmt: parts[0],
}
case 2:
rewrite = &rules.ReqPathRewrite{
PathMatch: parts[0],
PathFmt: parts[1],
}
default:
return fmt.Errorf("incorrect value '%s', path-rewrite takes 1 or 2 params ", input)
}
case 2:
rewrite = &rules.ReqPathRewrite{
PathMatch: parts[0],
PathFmt: parts[1],
}
default:
return fmt.Errorf("incorrect value '%s', path-rewrite takes 1 or 2 params ", input)
a.rules.Add(rewrite)
}
a.rules.Add(rewrite)
return
}

0 comments on commit effdda4

Please sign in to comment.