From b2141fa98eb5df139936163568b57539c82db57a Mon Sep 17 00:00:00 2001 From: Fabiano Parente Date: Thu, 9 Jan 2025 07:25:30 -0300 Subject: [PATCH 1/2] MINOR: remove redundancy in AddCustomRoute function logic Refactors the `AddCustomRoute` function to eliminate redundancy introduced in commit c28d620a. The updated code removes repetition without add extra spaces. --- pkg/route/route.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pkg/route/route.go b/pkg/route/route.go index 69b1e541..a5320ddf 100644 --- a/pkg/route/route.go +++ b/pkg/route/route.go @@ -107,17 +107,9 @@ func AddCustomRoute(route Route, routeACLAnn string, api api.HAProxyClient) (err } if route.Path.Path != "" { if route.Path.PathTypeMatch == store.PATH_TYPE_EXACT { - if routeCond == "" { - routeCond = fmt.Sprintf("{ path %s }", route.Path.Path) - } else { - routeCond = fmt.Sprintf("%s { path %s }", routeCond, route.Path.Path) - } + routeCond = fmt.Sprintf("%s{ path %s }", routeCond, route.Path.Path) } else { - if routeCond == "" { - routeCond = fmt.Sprintf("{ path -m beg %s }", route.Path.Path) - } else { - routeCond = fmt.Sprintf("%s { path -m beg %s }", routeCond, route.Path.Path) - } + routeCond = fmt.Sprintf("%s{ path -m beg %s }", routeCond, route.Path.Path) } } routeCond = fmt.Sprintf("%s { %s } ", routeCond, routeACLAnn) From 54bbfdf3b60d1e553ba58212e4c72592f008c8ea Mon Sep 17 00:00:00 2001 From: Fabiano Parente Date: Thu, 9 Jan 2025 07:37:41 -0300 Subject: [PATCH 2/2] MINOR: Refine route-acl rules to prevent unintended prefix matches Since `route-acl` annotated rules take precedence over others, this commit updates its behavior to ensure they do not unintentionally overwrite other rules that share the same prefix. For example, a rule matching the path /api should not inadvertently handle requests to /apiary. --- .aspell.yml | 1 + pkg/route/route.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.aspell.yml b/.aspell.yml index 1e29970d..fe89e527 100644 --- a/.aspell.yml +++ b/.aspell.yml @@ -1,6 +1,7 @@ mode: commit min_length: 3 allowed: + - acl - aspell - repo - yaml diff --git a/pkg/route/route.go b/pkg/route/route.go index a5320ddf..ed6c1fb6 100644 --- a/pkg/route/route.go +++ b/pkg/route/route.go @@ -109,7 +109,12 @@ func AddCustomRoute(route Route, routeACLAnn string, api api.HAProxyClient) (err if route.Path.PathTypeMatch == store.PATH_TYPE_EXACT { routeCond = fmt.Sprintf("%s{ path %s }", routeCond, route.Path.Path) } else { - routeCond = fmt.Sprintf("%s{ path -m beg %s }", routeCond, route.Path.Path) + if route.Path.Path == "/" { + routeCond = fmt.Sprintf("%s{ path -m beg %s }", routeCond, route.Path.Path) + } else { + path := strings.TrimSuffix(route.Path.Path, "/") + routeCond = fmt.Sprintf("%s{ path -m reg ^%s($|/) }", routeCond, path) + } } } routeCond = fmt.Sprintf("%s { %s } ", routeCond, routeACLAnn)