Skip to content

Commit

Permalink
Add config deployer changes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
sgayangi committed Jul 5, 2024
1 parent ae8d511 commit 55b3ba8
Show file tree
Hide file tree
Showing 14 changed files with 280 additions and 100 deletions.
31 changes: 15 additions & 16 deletions runtime/config-deployer-service/ballerina/APIClient.bal
Original file line number Diff line number Diff line change
Expand Up @@ -865,23 +865,22 @@ public class APIClient {
if policy is HeaderModifierPolicy {
HeaderModifierPolicyParameters policyParameters = policy.parameters;
match policy.policyName {
AddHeaders => {
ModifierHeader[] headers = <ModifierHeader[]>policyParameters.headers;
foreach ModifierHeader header in headers {
addHeaders.push(header);
}
AddHeader => {
model:HTTPHeader addHeader = {
name: policyParameters.headerName,
value: <string>policyParameters.headerValue
};
addHeaders.push(addHeader);
}
SetHeaders => {
ModifierHeader[] headers = <ModifierHeader[]>policyParameters.headers;
foreach ModifierHeader header in headers {
setHeaders.push(header);
}
SetHeader => {
model:HTTPHeader setHeader = {
name: policyParameters.headerName,
value: <string>policyParameters.headerValue
};
setHeaders.push(setHeader);
}
RemoveHeaders => {
string[] headers = <string[]>policyParameters.headers;
foreach string header in headers {
removeHeaders.push(header);
}
RemoveHeader => {
removeHeaders.push(policyParameters.headerName);
}
}
} else if policy is RequestMirrorPolicy {
Expand Down Expand Up @@ -1400,7 +1399,7 @@ public class APIClient {
model:BackendJWT backendJwt = self.retrieveBackendJWTPolicy(apkConf, apiArtifact, backendJWTPolicy, operations, organization);
apiArtifact.backendJwt = backendJwt;
policyReferences.push(<model:BackendJwtReference>{name: backendJwt.metadata.name});
} else if policyName != AddHeaders && policyName != SetHeaders && policyName != RemoveHeaders && policyName != RequestMirror && policyName != RequestRedirect {
} else if policyName != AddHeader && policyName != SetHeader && policyName != RemoveHeader && policyName != RequestMirror && policyName != RequestRedirect {
return e909052(error("Incorrect API Policy name provided."));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ components:
mapping:
BackendJwt: "#/components/schemas/BackendJWTPolicy"
Interceptor: "#/components/schemas/InterceptorPolicy"
AddHeaders: "#/components/schemas/HeaderModifierPolicy"
SetHeaders: "#/components/schemas/HeaderModifierPolicy"
RemoveHeaders: "#/components/schemas/HeaderModifierPolicy"
AddHeader: "#/components/schemas/HeaderModifierPolicy"
SetHeader: "#/components/schemas/HeaderModifierPolicy"
RemoveHeader: "#/components/schemas/HeaderModifierPolicy"
RequestMirror: "#/components/schemas/RequestMirrorPolicy"
RequestRedirect: "#/components/schemas/RequestRedirectPolicy"
BaseOperationPolicy:
Expand All @@ -278,9 +278,9 @@ components:
policyName:
type: string
enum:
- AddHeaders
- RemoveHeaders
- SetHeaders
- AddHeader
- RemoveHeader
- SetHeader
- Interceptor
- BackendJwt
policyVersion:
Expand Down Expand Up @@ -511,20 +511,13 @@ components:
title: Header Modifier Parameters
type: object
properties:
headers:
type: array
items:
oneOf:
- $ref: "#/components/schemas/Header"
- type: string
additionalProperties: false
Header:
type: object
properties:
name:
headerName:
type: string
value:
headerValue:
type: string
required:
- headerName
additionalProperties: false
RequestMirrorPolicy:
title: Request Mirror Parameters
type: object
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
21 changes: 7 additions & 14 deletions runtime/config-deployer-service/ballerina/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,11 @@ public type HeaderModifierPolicy record {

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

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

# Request mirror configuration for an operation.
Expand Down Expand Up @@ -373,9 +366,9 @@ public type BaseOperationPolicy record {
public enum PolicyName {
BackendJwt,
Interceptor,
AddHeaders,
SetHeaders,
RemoveHeaders,
AddHeader,
SetHeader,
RemoveHeader,
RequestMirror,
RequestRedirect
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@
"type": "string",
"description": "The name of the operation policy.",
"enum": [
"AddHeaders",
"RemoveHeaders",
"SetHeaders",
"AddHeader",
"RemoveHeader",
"SetHeader",
"Interceptor",
"BackendJwt",
"RequestMirror",
Expand Down Expand Up @@ -719,31 +719,20 @@
"title": "Header Modifier Parameters",
"type": "object",
"properties": {
"headers": {
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/schemas/Header"
},
{
"type": "string"
}
]
}
"headerName": {
"type": "string",
"description": "The name of the header."
},
"headerValue": {
"type": "string",
"description": "The value of the header."
}
},
"required": [
"headerName"
],
"additionalProperties": false
},
"Header": {
"type": "object",
"name": {
"type": "string"
},
"value": {
"type": "string"
}
},
"RequestMirrorProperties": {
"title": "Request Mirror Parameters",
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
id: "api-with-header-modifier-filters"
name: "EmployeeServiceAPI"
basePath: "/header-modifier-filters"
version: "3.14"
type: "REST"
defaultVersion: false
endpointConfigurations:
production:
endpoint: "http://backend:80/anything"
operations:
- target: "/employee"
verb: "GET"
secured: false
scopes: []
- target: "/employee"
verb: "POST"
secured: true
scopes: []
- target: "/employee/{employeeId}"
verb: "PUT"
secured: true
scopes: []
- target: "/employee/{employeeId}"
verb: "DELETE"
secured: true
scopes: []
apiPolicies:
request:
- policyName: AddHeader
policyVersion: v1
parameters:
headerName: "Test-Request-Header"
headerValue: "Test-Value"
- policyName: SetHeader
policyVersion: v1
parameters:
headerName: "Set-Request-Header"
headerValue: "Test-Value"
- policyName: RemoveHeader
policyVersion: v1
parameters:
headerName: "Authorization"
response:
- policyName: AddHeader
policyVersion: v1
parameters:
headerName: "Test-Response-Header"
headerValue: "Test-Value"
- policyName: SetHeader
policyVersion: v1
parameters:
headerName: "Set-Response-Header"
headerValue: "Test-Value"
- policyName: RemoveHeader
policyVersion: v1
parameters:
headerName: "content-type"
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
id: "api-with-request-mirror-filter"
name: "EmployeeServiceAPI"
basePath: "/request-mirror-filter"
version: "3.14"
type: "REST"
defaultVersion: false
endpointConfigurations:
production:
endpoint: "http://backend:80/anything"
operations:
- target: "/employee"
verb: "GET"
secured: false
scopes: []
- target: "/employee"
verb: "POST"
secured: true
scopes: []
- target: "/employee/{employeeId}"
verb: "PUT"
secured: true
scopes: []
- target: "/employee/{employeeId}"
verb: "DELETE"
secured: true
scopes: []
apiPolicies:
request:
- policyName: RequestMirror
policyVersion: v1
parameters:
urls:
- "http://backend:80/anything"
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
id: "api-with-request-redirect-filter"
name: "EmployeeServiceAPI"
basePath: "/request-redirect-filter"
version: "3.14"
type: "REST"
defaultVersion: false
endpointConfigurations:
production:
endpoint: "http://backend:80/anything"
operations:
- target: "/employee"
verb: "GET"
secured: false
scopes: []
- target: "/employee"
verb: "POST"
secured: true
scopes: []
- target: "/employee/{employeeId}"
verb: "PUT"
secured: true
scopes: []
- target: "/employee/{employeeId}"
verb: "DELETE"
secured: true
scopes: []
apiPolicies:
request:
- policyName: RequestRedirect
policyVersion: v1
parameters:
url: "http://backend:80/anything"
statusCode: 301
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,35 @@ operations:
scopes: []
operationPolicies:
request:
- policyName: AddHeaders
- policyName: AddHeader
policyVersion: v1
parameters:
headers:
- name: "Test-Request-Header"
value: "Test-Value"
- policyName: SetHeaders
headerName: "Test-Request-Header"
headerValue: "Test-Value"
- policyName: SetHeader
policyVersion: v1
parameters:
headers:
- name: "Set-Request-Header"
value: "Test-Value"
- policyName: RemoveHeaders
headerName: "Set-Request-Header"
headerValue: "Test-Value"
- policyName: RemoveHeader
policyVersion: v1
parameters:
headers:
- "Authorization"
headerName: "Authorization"
response:
- policyName: AddHeaders
- policyName: AddHeader
policyVersion: v1
parameters:
headers:
- name: "Test-Response-Header"
value: "Test-Value"
- policyName: SetHeaders
headerName: "Test-Response-Header"
headerValue: "Test-Value"
- policyName: SetHeader
policyVersion: v1
parameters:
headers:
- name: "Set-Response-Header"
value: "Test-Value"
- policyName: RemoveHeaders
headerName: "Set-Response-Header"
headerValue: "Test-Value"
- policyName: RemoveHeader
policyVersion: v1
parameters:
headers:
- "content-type"
headerName: "content-type"
- target: "/employee"
verb: "POST"
secured: true
Expand Down
Loading

0 comments on commit 55b3ba8

Please sign in to comment.