File tree 3 files changed +128
-2
lines changed
3 files changed +128
-2
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ local profile = require("apisix.core.profile")
23
23
local template = require (" resty.template" )
24
24
local argparse = require (" argparse" )
25
25
local pl_path = require (" pl.path" )
26
+ local jsonschema = require (" jsonschema" )
26
27
27
28
local stderr = io.stderr
28
29
local ipairs = ipairs
@@ -144,6 +145,125 @@ local function get_lua_path(conf)
144
145
end
145
146
146
147
148
+ local config_schema = {
149
+ type = " object" ,
150
+ properties = {
151
+ apisix = {
152
+ properties = {
153
+ config_center = {
154
+ enum = {" etcd" , " yaml" },
155
+ },
156
+ proxy_protocol = {
157
+ type = " object" ,
158
+ properties = {
159
+ listen_http_port = {
160
+ type = " integer" ,
161
+ },
162
+ listen_https_port = {
163
+ type = " integer" ,
164
+ },
165
+ enable_tcp_pp = {
166
+ type = " boolean" ,
167
+ },
168
+ enable_tcp_pp_to_upstream = {
169
+ type = " boolean" ,
170
+ },
171
+ }
172
+ },
173
+ port_admin = {
174
+ type = " integer" ,
175
+ },
176
+ https_admin = {
177
+ type = " boolean" ,
178
+ },
179
+ stream_proxy = {
180
+ type = " object" ,
181
+ properties = {
182
+ tcp = {
183
+ type = " array" ,
184
+ minItems = 1 ,
185
+ items = {
186
+ type = " integer" ,
187
+ }
188
+ },
189
+ udp = {
190
+ type = " array" ,
191
+ minItems = 1 ,
192
+ items = {
193
+ type = " integer" ,
194
+ }
195
+ },
196
+ }
197
+ },
198
+ dns_resolver = {
199
+ type = " array" ,
200
+ minItems = 1 ,
201
+ items = {
202
+ type = " string" ,
203
+ }
204
+ },
205
+ dns_resolver_valid = {
206
+ type = " integer" ,
207
+ },
208
+ ssl = {
209
+ type = " object" ,
210
+ properties = {
211
+ ssl_trusted_certificate = {
212
+ type = " string" ,
213
+ }
214
+ }
215
+ },
216
+ }
217
+ },
218
+ nginx_config = {
219
+ type = " object" ,
220
+ properties = {
221
+ envs = {
222
+ type = " array" ,
223
+ minItems = 1 ,
224
+ items = {
225
+ type = " string" ,
226
+ }
227
+ }
228
+ },
229
+ },
230
+ http = {
231
+ type = " object" ,
232
+ properties = {
233
+ lua_shared_dicts = {
234
+ type = " object" ,
235
+ }
236
+ }
237
+ },
238
+ etcd = {
239
+ type = " object" ,
240
+ properties = {
241
+ resync_delay = {
242
+ type = " integer" ,
243
+ },
244
+ user = {
245
+ type = " string" ,
246
+ },
247
+ password = {
248
+ type = " string" ,
249
+ },
250
+ tls = {
251
+ type = " object" ,
252
+ properties = {
253
+ cert = {
254
+ type = " string" ,
255
+ },
256
+ key = {
257
+ type = " string" ,
258
+ },
259
+ }
260
+ }
261
+ }
262
+ }
263
+ }
264
+ }
265
+
266
+
147
267
local function init (env )
148
268
if env .is_root_path then
149
269
print (' Warning! Running apisix under /root is only suitable for '
@@ -158,6 +278,12 @@ local function init(env)
158
278
util .die (" failed to read local yaml config of apisix: " , err , " \n " )
159
279
end
160
280
281
+ local validator = jsonschema .generate_validator (config_schema )
282
+ local ok , err = validator (yaml_conf )
283
+ if not ok then
284
+ util .die (" failed to validate config: " , err , " \n " )
285
+ end
286
+
161
287
-- check the Admin API token
162
288
local checked_admin_key = false
163
289
if yaml_conf .apisix .enable_admin and yaml_conf .apisix .allow_admin then
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ dependencies = {
50
50
" luafilesystem = 1.7.0-2" ,
51
51
" lua-tinyyaml = 1.0" ,
52
52
" nginx-lua-prometheus = 0.20201218" ,
53
- " jsonschema = 0.9.4 " ,
53
+ " jsonschema = 0.9.5 " ,
54
54
" lua-resty-ipmatcher = 0.6" ,
55
55
" lua-resty-kafka = 0.07" ,
56
56
" lua-resty-logger-socket = 2.0-0" ,
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ apisix:
27
27
' > conf/config.yaml
28
28
29
29
out=$( make init 2>&1 || true)
30
- if ! echo " $out " | grep ' dns_resolver_valid should be a number ' ; then
30
+ if ! echo " $out " | grep ' property " dns_resolver_valid" validation failed: wrong type: expected integer, got string ' ; then
31
31
echo " failed: dns_resolver_valid should be a number"
32
32
exit 1
33
33
fi
You can’t perform that action at this time.
0 commit comments