Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null pointer in enforcer #2546

Merged
merged 1 commit into from
Oct 8, 2024
Merged
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
49 changes: 33 additions & 16 deletions adapter/internal/oasparser/model/adapter_internal_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,17 +753,32 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoHTTPRouteCR(httpRoute *gwap
})
}
case gwapiv1.HTTPRouteFilterRequestRedirect:
var requestRedirectEndpoint Endpoint
hasRequestRedirectPolicy = true
policyParameters := make(map[string]interface{})

policyParameters[constants.RedirectScheme] = *filter.RequestRedirect.Scheme
policyParameters[constants.RedirectHostname] = string(*filter.RequestRedirect.Hostname)
if filter.RequestRedirect.Port != nil {
policyParameters[constants.RedirectPort] = strconv.Itoa(int(*filter.RequestRedirect.Port))
scheme := *filter.RequestRedirect.Scheme
host := string(*filter.RequestRedirect.Hostname)
port := filter.RequestRedirect.Port
code := filter.RequestRedirect.StatusCode

policyParameters[constants.RedirectScheme] = scheme
requestRedirectEndpoint.URLType = scheme
policyParameters[constants.RedirectHostname] = host
requestRedirectEndpoint.Host = host

if port != nil {
policyParameters[constants.RedirectPort] = strconv.Itoa(int(*port))
requestRedirectEndpoint.Port = uint32(*port)
} else {
if requestRedirectEndpoint.URLType == "http" {
requestRedirectEndpoint.Port = 80
} else if requestRedirectEndpoint.URLType == "https" {
requestRedirectEndpoint.Port = 443
}
}

if filter.RequestRedirect.StatusCode != nil {
policyParameters[constants.RedirectStatusCode] = *filter.RequestRedirect.StatusCode
if code != nil {
policyParameters[constants.RedirectStatusCode] = *code
}

switch filter.RequestRedirect.Path.Type {
Expand All @@ -772,12 +787,14 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoHTTPRouteCR(httpRoute *gwap
case gwapiv1.PrefixMatchHTTPPathModifier:
policyParameters[constants.RedirectPath] = backendBasePath + *filter.RequestRedirect.Path.ReplacePrefixMatch
}
requestRedirectEndpoint.Basepath = policyParameters[constants.RedirectPath].(string)

policies.Request = append(policies.Request, Policy{
PolicyName: string(gwapiv1.HTTPRouteFilterRequestRedirect),
Action: constants.ActionRedirectRequest,
Parameters: policyParameters,
})
endPoints = append(endPoints, requestRedirectEndpoint)

case gwapiv1.HTTPRouteFilterRequestMirror:
var mirrorTimeoutInMillis uint32
Expand Down Expand Up @@ -917,17 +934,17 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoHTTPRouteCR(httpRoute *gwap
matchID := getMatchID(httpRoute.Namespace, httpRoute.Name, ruleID, matchID)
operations := getAllowedOperations(matchID, match.Method, policies, apiAuth,
parseRateLimitPolicyToInternal(resourceRatelimitPolicy), scopes, mirrorEndpointClusters)

resource := &Resource{
path: resourcePath,
methods: operations,
pathMatchType: *match.Path.Type,
hasPolicies: true,
iD: uuid.New().String(),
hasRequestRedirectFilter: hasRequestRedirectPolicy,
enableBackendBasedAIRatelimit: enableBackendBasedAIRatelimit,
path: resourcePath,
methods: operations,
pathMatchType: *match.Path.Type,
hasPolicies: true,
iD: uuid.New().String(),
hasRequestRedirectFilter: hasRequestRedirectPolicy,
enableBackendBasedAIRatelimit: enableBackendBasedAIRatelimit,
backendBasedAIRatelimitDescriptorValue: descriptorValue,
extractTokenFrom: extractTokenFrom,
extractTokenFrom: extractTokenFrom,
}

resource.endpoints = &EndpointCluster{
Expand Down
Loading