Skip to content

Commit 0ff467b

Browse files
committed
Add policy definition
1 parent 4b7069c commit 0ff467b

File tree

1 file changed

+182
-0
lines changed

1 file changed

+182
-0
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
name: request-rewrite
2+
version: v0.1.0
3+
description: |
4+
Rewrites incoming requests by updating paths, query parameters, and/or HTTP methods before forwarding to upstream services.
5+
Supports multiple path rewrite types: prefix replacement, full path replacement, and regex-based substitution.
6+
Supports query parameter rewrite rules (replace, remove, add, append, and regex-based substitution).
7+
Method rewriting changes the HTTP method of the request.
8+
Optional match conditions allow rewrites to apply only when headers and/or query parameters match.
9+
10+
parameters:
11+
type: object
12+
properties:
13+
match:
14+
type: object
15+
description: Optional match conditions that gate whether rewrites are applied
16+
properties:
17+
headers:
18+
type: array
19+
description: All header matchers must succeed for the policy to apply
20+
minItems: 1
21+
items:
22+
type: object
23+
properties:
24+
name:
25+
type: string
26+
description: Header name to match (case-insensitive)
27+
minLength: 1
28+
type:
29+
type: string
30+
description: Match type for the header
31+
enum:
32+
- Exact
33+
- Regex
34+
- Present
35+
value:
36+
type: string
37+
description: Value to match (required for Exact and Regex)
38+
minLength: 1
39+
maxLength: 2048
40+
required:
41+
- name
42+
- type
43+
queryParams:
44+
type: array
45+
description: All query param matchers must succeed for the policy to apply
46+
minItems: 1
47+
items:
48+
type: object
49+
properties:
50+
name:
51+
type: string
52+
description: Query parameter name to match
53+
minLength: 1
54+
type:
55+
type: string
56+
description: Match type for the query parameter
57+
enum:
58+
- Exact
59+
- Regex
60+
- Present
61+
value:
62+
type: string
63+
description: Value to match (required for Exact and Regex)
64+
minLength: 1
65+
maxLength: 2048
66+
required:
67+
- name
68+
- type
69+
minProperties: 1
70+
pathRewrite:
71+
type: object
72+
description: Configuration for rewriting the request path
73+
properties:
74+
type:
75+
type: string
76+
description: The type of path rewrite to perform
77+
enum:
78+
- ReplacePrefixMatch
79+
- ReplaceFullPath
80+
- ReplaceRegexMatch
81+
replacePrefixMatch:
82+
type: string
83+
description: |
84+
The value to replace the matched prefix with.
85+
Required when type is ReplacePrefixMatch.
86+
The prefix to match is determined by the operation path this policy is attached to.
87+
maxLength: 2048
88+
replaceFullPath:
89+
type: string
90+
description: |
91+
The exact path to replace the entire request path with.
92+
Required when type is ReplaceFullPath.
93+
minLength: 1
94+
maxLength: 2048
95+
pattern: "^/.*"
96+
replaceRegexMatch:
97+
type: object
98+
description: |
99+
Regex-based path rewrite configuration.
100+
Required when type is ReplaceRegexMatch.
101+
Uses RE2 regex syntax: https://github.com/google/re2/wiki/Syntax
102+
properties:
103+
pattern:
104+
type: string
105+
description: Regular expression pattern to match against the path
106+
minLength: 1
107+
maxLength: 1024
108+
substitution:
109+
type: string
110+
description: |
111+
Replacement string. May include numbered capture groups (e.g., \1, \2).
112+
maxLength: 2048
113+
required:
114+
- pattern
115+
- substitution
116+
required:
117+
- type
118+
queryRewrite:
119+
type: object
120+
description: Configuration for rewriting query parameters
121+
properties:
122+
rules:
123+
type: array
124+
description: List of query parameter rewrite rules, applied in order
125+
minItems: 1
126+
items:
127+
type: object
128+
properties:
129+
action:
130+
type: string
131+
description: Rewrite action to apply
132+
enum:
133+
- Replace
134+
- Remove
135+
- Add
136+
- Append
137+
- ReplaceRegexMatch
138+
name:
139+
type: string
140+
description: Query parameter name to target
141+
minLength: 1
142+
value:
143+
type: string
144+
description: Value used by Replace, Add, and Append
145+
maxLength: 2048
146+
separator:
147+
type: string
148+
description: Optional separator used by Append (default is empty string)
149+
maxLength: 64
150+
pattern:
151+
type: string
152+
description: Regular expression pattern to match against the parameter value
153+
minLength: 1
154+
maxLength: 1024
155+
substitution:
156+
type: string
157+
description: Replacement string (supports \1, \2, etc. for capture groups)
158+
maxLength: 2048
159+
required:
160+
- action
161+
- name
162+
required:
163+
- rules
164+
methodRewrite:
165+
type: string
166+
description: HTTP method to change the request to
167+
enum:
168+
- GET
169+
- POST
170+
- PUT
171+
- DELETE
172+
- PATCH
173+
- HEAD
174+
- OPTIONS
175+
anyOf:
176+
- required: [pathRewrite]
177+
- required: [queryRewrite]
178+
- required: [methodRewrite]
179+
180+
systemParameters:
181+
type: object
182+
properties: {}

0 commit comments

Comments
 (0)