Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions adapter/internal/oasparser/model/adapter_internal_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,9 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoHTTPRouteCR(ctx context.Con

switch filter.URLRewrite.Path.Type {
case gwapiv1.FullPathHTTPPathModifier:
policyParameters[constants.RewritePathResourcePath] = backendBasePath + *filter.URLRewrite.Path.ReplaceFullPath
policyParameters[constants.RewritePathResourcePath] = joinPaths(backendBasePath, *filter.URLRewrite.Path.ReplaceFullPath)
case gwapiv1.PrefixMatchHTTPPathModifier:
policyParameters[constants.RewritePathResourcePath] = backendBasePath + *filter.URLRewrite.Path.ReplacePrefixMatch
policyParameters[constants.RewritePathResourcePath] = joinPaths(backendBasePath, *filter.URLRewrite.Path.ReplacePrefixMatch)
}

policies.Request = append(policies.Request, Policy{
Expand Down Expand Up @@ -879,9 +879,9 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoHTTPRouteCR(ctx context.Con

switch filter.RequestRedirect.Path.Type {
case gwapiv1.FullPathHTTPPathModifier:
policyParameters[constants.RedirectPath] = backendBasePath + *filter.RequestRedirect.Path.ReplaceFullPath
policyParameters[constants.RedirectPath] = joinPaths(backendBasePath, *filter.RequestRedirect.Path.ReplaceFullPath)
case gwapiv1.PrefixMatchHTTPPathModifier:
policyParameters[constants.RedirectPath] = backendBasePath + *filter.RequestRedirect.Path.ReplacePrefixMatch
policyParameters[constants.RedirectPath] = joinPaths(backendBasePath, *filter.RequestRedirect.Path.ReplacePrefixMatch)
}
requestRedirectEndpoint.Basepath = policyParameters[constants.RedirectPath].(string)

Expand Down Expand Up @@ -1019,14 +1019,14 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoHTTPRouteCR(ctx context.Con
policyParameters[constants.RewritePathType] = gwapiv1.FullPathHTTPPathModifier
}
policyParameters[constants.IncludeQueryParams] = true
policyParameters[constants.RewritePathResourcePath] = strings.TrimSuffix(backendBasePath, "/") + *match.Path.Value
policyParameters[constants.RewritePathResourcePath] = joinPaths(backendBasePath, *match.Path.Value)
policies.Request = append(policies.Request, Policy{
PolicyName: string(gwapiv1.HTTPRouteFilterURLRewrite),
Action: constants.ActionRewritePath,
Parameters: policyParameters,
})
}
resourcePath := adapterInternalAPI.xWso2Basepath + *match.Path.Value
resourcePath := joinPaths(adapterInternalAPI.xWso2Basepath, *match.Path.Value)
matchID := getMatchID(httpRoute.Namespace, httpRoute.Name, ruleID, matchID)
operations := getAllowedOperations(matchID, match.Method, policies, apiAuth,
parseRateLimitPolicyToInternal(resourceRatelimitPolicy), scopes, mirrorEndpointClusters)
Expand Down Expand Up @@ -2151,6 +2151,41 @@ func CreateDummyAdapterInternalAPIForTests(title, version, basePath string, reso
}
}

// joinPaths safely concatenates basePath and path, handling various edge cases
func joinPaths(basePath, path string) string {
// Trim spaces from both inputs
basePath = strings.TrimSpace(basePath)
path = strings.TrimSpace(path)

// Handle empty basePath
if basePath == "" {
return path
}

// Handle empty path
if path == "" {
return basePath
}

// If basePath is just "/", return the path as is to avoid "//" prefix
if basePath == "/" {
return path
}

// Handle case where path doesn't start with "/" but basePath doesn't end with "/"
// This ensures proper path formation
if !strings.HasSuffix(basePath, "/") && !strings.HasPrefix(path, "/") {
return basePath + "/" + path
}

// Handle double slash case where basePath ends with "/" and path starts with "/"
if strings.HasSuffix(basePath, "/") && strings.HasPrefix(path, "/") {
return basePath + strings.TrimPrefix(path, "/")
}

return basePath + path
}

func prepareAIRatelimitIdentifier(org string, namespacedName types.NamespacedName, spec *dpv1alpha3.AIRateLimitPolicySpec) string {
targetNamespace := string(namespacedName.Namespace)
if spec.TargetRef.Namespace != nil && string(*spec.TargetRef.Namespace) != "" {
Expand Down
2 changes: 1 addition & 1 deletion helm-charts/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: choreo-apk
description: A Helm chart for APK components
type: application
version: 1.3.0-24
version: 1.3.0-25
appVersion: "1.3.0"
dependencies:
- name: postgresql
Expand Down
Loading