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

Add request redirect and mirror filters to config deployer #2392

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 4 additions & 10 deletions adapter/internal/oasparser/envoyconf/routes_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func generateRouteAction(apiType string, routeConfig *model.EndpointConfig, rate
return action
}

func generateRequestRedirectRoute(route string, policyParams interface{}) (action *routev3.Route_Redirect) {
func generateRequestRedirectRoute(route string, policyParams interface{}) (*routev3.Route_Redirect, error) {
policyParameters, _ := policyParams.(map[string]interface{})
scheme, _ := policyParameters[constants.RedirectScheme].(string)
hostname, _ := policyParameters[constants.RedirectHostname].(string)
Expand All @@ -137,10 +137,10 @@ func generateRequestRedirectRoute(route string, policyParams interface{}) (actio
replaceFullPath, _ := policyParameters[constants.RedirectPath].(string)
redirectActionStatusCode := mapStatusCodeToEnum(statusCode)
if redirectActionStatusCode == -1 {
_ = fmt.Errorf("Invalid status code provided")
return nil, fmt.Errorf("Invalid status code provided")
}

action = &routev3.Route_Redirect{
action := &routev3.Route_Redirect{
Redirect: &routev3.RedirectAction{
SchemeRewriteSpecifier: &routev3.RedirectAction_HttpsRedirect{
HttpsRedirect: scheme == "https",
Expand All @@ -153,7 +153,7 @@ func generateRequestRedirectRoute(route string, policyParams interface{}) (actio
ResponseCode: routev3.RedirectAction_RedirectResponseCode(redirectActionStatusCode),
},
}
return action
return action, nil
}

func mapStatusCodeToEnum(statusCode int) int {
Expand All @@ -162,12 +162,6 @@ func mapStatusCodeToEnum(statusCode int) int {
return 0
case 302:
return 1
case 303:
return 2
case 307:
return 3
case 308:
return 4
default:
return -1
}
Expand Down
5 changes: 4 additions & 1 deletion adapter/internal/oasparser/envoyconf/routes_with_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,10 @@ func createRoutes(params *routeCreateParams) (routes []*routev3.Route, err error
case constants.ActionRedirectRequest:
logger.LoggerOasparser.Debugf("Adding %s policy to request flow for %s %s",
constants.ActionRedirectRequest, resourcePath, operation.GetMethod())
requestRedirectAction = generateRequestRedirectRoute(resourcePath, requestPolicy.Parameters)
requestRedirectAction, err = generateRequestRedirectRoute(resourcePath, requestPolicy.Parameters)
if err != nil {
return nil, err
}
}
}

Expand Down
268 changes: 197 additions & 71 deletions runtime/config-deployer-service/ballerina/APIClient.bal

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public type HTTPQueryParamMatch record {
};

public type HTTPRouteMatch record {

HTTPPathMatch path?;
HTTPHeaderMatch headers?;
HTTPQueryParamMatch queryParams?;
Expand Down Expand Up @@ -79,14 +78,13 @@ public type HTTPRequestRedirectFilter record {
string scheme?;
string hostname?;
HTTPPathModifier path?;
string port?;
int port?;
int statusCode?;
};

public type HTTPURLRewriteFilter record {
string hostname?;
HTTPPathModifier path?;

};

public type LocalObjectReference record {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,44 @@ components:
request:
type: array
items:
$ref: "#/components/schemas/APKOperationPolicy"
$ref: "#/components/schemas/APKRequestOperationPolicy"
response:
type: array
items:
$ref: "#/components/schemas/APKOperationPolicy"
$ref: "#/components/schemas/APKResponseOperationPolicy"
additionalProperties: false
APKOperationPolicy:
APKRequestOperationPolicy:
title: API Operation Policy
oneOf:
- $ref: "#/components/schemas/InterceptorPolicy"
- $ref: "#/components/schemas/BackendJWTPolicy"
- $ref: "#/components/schemas/HeaderModifierPolicy"
- $ref: "#/components/schemas/RequestMirrorPolicy"
- $ref: "#/components/schemas/RequestRedirectPolicy"
discriminator:
propertyName: "policyName"
mapping:
BackendJwt: "#/components/schemas/BackendJWTPolicy"
Interceptor: "#/components/schemas/InterceptorPolicy"
AddHeaders: "#/components/schemas/HeaderModifierPolicy"
SetHeaders: "#/components/schemas/HeaderModifierPolicy"
RemoveHeadersHeaders: "#/components/schemas/HeaderModifierPolicy"
AddHeader: "#/components/schemas/HeaderModifierPolicy"
SetHeader: "#/components/schemas/HeaderModifierPolicy"
RemoveHeader: "#/components/schemas/HeaderModifierPolicy"
RequestMirror: "#/components/schemas/RequestMirrorPolicy"
RequestRedirect: "#/components/schemas/RequestRedirectPolicy"
APKResponseOperationPolicy:
title: API Operation Policy
oneOf:
- $ref: "#/components/schemas/InterceptorPolicy"
- $ref: "#/components/schemas/BackendJWTPolicy"
- $ref: "#/components/schemas/HeaderModifierPolicy"
discriminator:
propertyName: "policyName"
mapping:
BackendJwt: "#/components/schemas/BackendJWTPolicy"
Interceptor: "#/components/schemas/InterceptorPolicy"
AddHeader: "#/components/schemas/HeaderModifierPolicy"
SetHeader: "#/components/schemas/HeaderModifierPolicy"
RemoveHeader: "#/components/schemas/HeaderModifierPolicy"
BaseOperationPolicy:
title: API Operation Policy
required:
Expand All @@ -274,9 +292,9 @@ components:
policyName:
type: string
enum:
- AddHeaders
- RemoveHeaders
- SetHeaders
- AddHeader
- RemoveHeader
- SetHeader
- Interceptor
- BackendJwt
policyVersion:
Expand Down Expand Up @@ -507,20 +525,37 @@ components:
title: Header Modifier Parameters
type: object
properties:
headers:
headerName:
type: string
headerValue:
type: string
required:
- headerName
additionalProperties: false
RequestMirrorPolicy:
title: Request Mirror Parameters
type: object
properties:
urls:
type: array
items:
oneOf:
- $ref: "#/components/schemas/Header"
- type: string
- type: string
additionalProperties: false
Header:
RequestRedirectPolicy:
title: Request Redirect Parameters
type: object
properties:
name:
type: string
value:
url:
type: string
description: The URL to redirect the request to.
statusCode:
type: integer
description: The status code to show upon redirecting the request.
default: 302
enum:
- 301
- 302
additionalProperties: false
CustomClaims:
type: object
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@
"type": "string",
"description": "The name of the operation policy.",
"enum": [
"AddHeaders",
"RemoveHeaders",
"SetHeaders",
"AddHeader",
"RemoveHeader",
"SetHeader",
"Interceptor",
"BackendJwt"
]
Expand Down
105 changes: 63 additions & 42 deletions runtime/config-deployer-service/ballerina/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,62 @@ public type APKOperations record {
string[] scopes?;
};

# Common type for operation policies.
public type APKOperationPolicy InterceptorPolicy|BackendJWTPolicy|HeaderModifierPolicy;
public type APKOperationPolicy APKRequestOperationPolicy|APKResponseOperationPolicy;

# Common type for request operation policies.
public type APKRequestOperationPolicy InterceptorPolicy|BackendJWTPolicy|HeaderModifierPolicy|RequestMirrorPolicy|RequestRedirectPolicy;

# Common type for response operation policies.
public type APKResponseOperationPolicy InterceptorPolicy|BackendJWTPolicy|HeaderModifierPolicy;

# Header modification configuration for an operation.
#
# + parameters - Contains header name and value of the header.
public type HeaderModifierPolicy record {
*BaseOperationPolicy;
HeaderModifierPolicyParameters parameters;
};

# Configuration for header modifiers as received from the apk-conf file.
#
# + headerName - Header name to be added, set or removed.
# + headerValue - Header value to be added, set or removed.
public type HeaderModifierPolicyParameters record {|
string headerName;
string headerValue?;
|};

# Request mirror configuration for an operation.
#
# + parameters - Contains the urls to request the mirror to.
public type RequestMirrorPolicy record {
*BaseOperationPolicy;
RequestMirrorPolicyParameters parameters;
};

# Configuration containing the different headers.
#
# + urls - The urls to mirror the filters to.
public type RequestMirrorPolicyParameters record {|
string[] urls;
|};

# Request redirect configuration for an operation.
#
# + parameters - Contains the url to redirect the request to.
public type RequestRedirectPolicy record {
*BaseOperationPolicy;
RequestRedirectPolicyParameters parameters;
};

# Configuration containing the different headers.
#
# + url - The url to redirect the filters to.
# + statusCode - The status code to be sent as response to the client.
public type RequestRedirectPolicyParameters record {|
string url;
int statusCode?;
|};

# Configuration for API deployment using the apk-conf file.
#
Expand All @@ -143,8 +197,8 @@ public type DeployApiBody record {
# + request - List of policies to be applied on the request.
# + response - List of policies to be applied on the response.
public type APIOperationPolicies record {
APKOperationPolicy[] request?;
APKOperationPolicy[] response?;
APKRequestOperationPolicy[] request?;
APKResponseOperationPolicy[] response?;
};

# Additional properties for APK configuration.
Expand Down Expand Up @@ -317,9 +371,11 @@ public type BaseOperationPolicy record {
public enum PolicyName {
BackendJwt,
Interceptor,
AddHeaders,
SetHeaders,
RemoveHeaders
AddHeader,
SetHeader,
RemoveHeader,
RequestMirror,
RequestRedirect
}

# Configuration for authentication types.
Expand All @@ -331,14 +387,6 @@ public type Authentication record {|
boolean enabled = true;
|};

# Header modification configuration for an operation.
#
# + parameters - Contains header name and value of the header.
public type HeaderModifierPolicy record {
*BaseOperationPolicy;
HeaderModifierPolicyParameters parameters;
};

# Interceptor policy configuration for an operation.
#
# + parameters - Contains interceptor policy parameters
Expand Down Expand Up @@ -387,33 +435,6 @@ public type APKConf record {
CORSConfiguration corsConfiguration?;
};

# Configuration for header modifiers as received from the apk-conf file.
#
# + headers - Headers to be added, set or removed.
public type HeaderModifierPolicyParameters record {|
ModifierHeader[]|string[] headers;
|};

# Configuration containing the different headers.
#
# + addHeaders - Headers to be added.
# + setHeaders - Headers to be set.
# + removeHeaders - Headers to be removed.
public type HeaderModifierFilterParameters record {|
ModifierHeader[] addHeaders;
ModifierHeader[] setHeaders;
string[] removeHeaders;
|};

# Configuration for headers.
#
# + name - The name of the header.
# + value - The value of the header.
public type ModifierHeader record {|
string name;
string value;
|};

# Configuration for Interceptor Policy parameters.
#
# + backendUrl - Backend URL of the interceptor service.
Expand Down
Loading
Loading