-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrules.py
More file actions
211 lines (208 loc) · 8.75 KB
/
rules.py
File metadata and controls
211 lines (208 loc) · 8.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
HTTP_HEADER_FILTER_SCHEMA = {
"set": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"value": {"type": "string"}
}
}
},
"add": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"value": {"type": "string"}
}
}
},
"remove": {"type": "array"}
}
FILTER_SCHEMA = {
# Type identifies the type of filter to apply.
# As with other API fields, types are classified into three conformance levels:
"type": {
"type": "string",
"enum": ["ExtensionRef", "RequestHeaderModifier", "RequestMirror", "RequestRedirect", "ResponseHeaderModifier", "URLRewrite"], # noqa
},
# ExtensionRef is an optional, implementation-specific extension to the “filter” behavior. # noqa
# For example, resource “myroutefilter” in group “networking.example.net”).
# ExtensionRef MUST NOT be used for core and extended filters.
"extensionRef": {
"type": "object",
"properties": {
"group": {"type": "string"},
"kind": {"type": "string"},
"name": {"type": "string"}
},
"required": ["group", "kind", "name"],
"additionalProperties": False
},
# RequestHeaderModifier defines a schema for a filter that modifies request headers.
"requestHeaderModifier": {
"type": "object",
"properties": HTTP_HEADER_FILTER_SCHEMA,
"additionalProperties": False
},
# ResponseHeaderModifier defines a schema for a filter that modifies response headers.
"responseHeaderModifier": {
"type": "object",
"properties": HTTP_HEADER_FILTER_SCHEMA,
"additionalProperties": False
},
# RequestMirror defines a schema for a filter that mirrors requests.
# Requests are sent to the specified destination, but responses from that destination are ignored. # noqa
"requestMirror": {
"type": "object",
"properties": {
"backendRef": {
"properties": {
"group": {"type": "string"},
"kind": {"type": "string"},
"name": {"type": "string"},
"namespace": {"type": "string"},
"port": {"type": "integer"},
},
"required": ["name"],
"additionalProperties": False
},
},
"required": ["backendRef"],
"additionalProperties": False
},
# RequestRedirect defines a schema for a filter that responds to the request with an HTTP redirection. # noqa
"requestRedirect": {
"type": "object",
"properties": {
"scheme": {"type": "string"},
"hostname": {"type": "string"},
"path": {"type": "string"},
"port": {"type": "integer"},
"statusCode": {"type": "integer"}
}
},
# URLRewrite defines a schema for a filter that modifies a request during forwarding
"urlRewrite": {
"hostname": {"type": "string"},
"path": {"type": "string"},
}
}
RULES_SCHEMA = {
"type": "array",
"items": {
"properties": {
# Matches define conditions used for matching the rule against incoming HTTP requests. # noqa
# Each match is independent, i.e. this rule will be matched if any one of the matches is satisfied. # noqa
# More info: https://gateway-api.sigs.k8s.io/references/spec/#gateway.networking.k8s.io/v1beta1.HTTPRouteMatch # noqa
"matches": {
"type": "array",
"items": {
"properties": {
# Path specifies a HTTP request path matcher.
# If this field is not specified, a default prefix match on the “/” path is provided. # noqa
"path": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["Exact", "PathPrefix", "RegularExpression"],
"default": "PathPrefix"
},
"value": {"type": "string"}
},
"additionalProperties": False
},
# Headers specifies HTTP request header matchers. Multiple match values are ANDed together, # noqa
# meaning, a request must match all the specified headers to select the route. # noqa
# gateway.networking.k8s.io/v1beta1.HTTPHeaderMatch
# More info: https: // gateway-api.sigs.k8s.io/references/spec /
"headers": {
"type": "array",
"items": {
"properties": {
"type": {
"type": "string",
"enum": ["Exact", "RegularExpression"],
"default": "Exact"
},
"name": {"type": "string"},
"value": {"type": "string"}
},
"additionalProperties": False
}
},
# QueryParams specifies HTTP query parameter matchers. Multiple match values are ANDed together, # noqa
# meaning, a request must match all the specified query parameters to select the route. # noqa
"queryParams": {
"type": "array",
"items": {
"properties": {
"type": {
"type": "string",
"enum": ["Exact", "RegularExpression"],
"default": "Exact"
},
"name": {"type": "string"},
"value": {"type": "string"}
},
"additionalProperties": False
}
},
"method": {
"type": "string",
"enum": ["CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "TRACE"], # noqa
}
},
"additionalProperties": False
}
},
# Filters define the filters that are applied to requests that match this rule.
# More info: https://gateway-api.sigs.k8s.io/references/spec/#gateway.networking.k8s.io/v1beta1.HTTPRouteFilter # noqa
"filters": {
"type": "array",
"items": {
"properties": FILTER_SCHEMA,
"additionalProperties": False
},
},
# BackendRefs defines the backend(s) where matching requests should be sent.
# More info: https://gateway-api.sigs.k8s.io/references/spec/#gateway.networking.k8s.io/v1beta1.HTTPBackendRef # noqa
"backendRefs": {
"type": "array",
"items": {
"properties": {
"filters": {
"type": "array",
"items": {
"properties": FILTER_SCHEMA,
"additionalProperties": False
},
},
"group": {"type": "string"},
"kind": {"type": "string"},
"name": {"type": "string"},
"namespace": {"type": "string"},
"port": {"type": "integer"},
"weight": {"type": "integer"}
},
"required": ["name"],
"additionalProperties": False
}
}
},
"required": ["backendRefs"],
"additionalProperties": False
}
}
SCHEMA = {
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"canary": RULES_SCHEMA,
"stable": RULES_SCHEMA,
},
"required": ["canary", "stable"],
"additionalProperties": False
}