Skip to content

Commit

Permalink
Fix null pointer in enforcer
Browse files Browse the repository at this point in the history
  • Loading branch information
sgayangi committed Oct 7, 2024
1 parent cbcad45 commit e512303
Showing 1 changed file with 33 additions and 16 deletions.
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

0 comments on commit e512303

Please sign in to comment.