This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new b1a9114 fix: validation during merging node_listen configuration
(#4881)
b1a9114 is described below
commit b1a9114cc0c308637fd9864ce40e2b78d35b3b0c
Author: Way2go <[email protected]>
AuthorDate: Fri Aug 27 16:14:24 2021 +0800
fix: validation during merging node_listen configuration (#4881)
---
apisix/cli/file.lua | 25 +++++++++++++++++++++----
conf/config-default.yaml | 4 +++-
t/cli/test_validate_config.sh | 20 ++++++++++++++++++++
t/core/config-default.t | 4 ++--
4 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/apisix/cli/file.lua b/apisix/cli/file.lua
index 892e335..b4d51fb 100644
--- a/apisix/cli/file.lua
+++ b/apisix/cli/file.lua
@@ -112,6 +112,24 @@ local function tinyyaml_type(t)
end
+local function path_is_multi_type(path, type_val)
+ if str_sub(path, 1, 14) == "nginx_config->" and
+ (type_val == "number" or type_val == "string") then
+ return true
+ end
+
+ if path == "apisix->node_listen" and type_val == "number" then
+ return true
+ end
+
+ if path == "apisix->ssl->listen_port" and type_val == "number" then
+ return true
+ end
+
+ return false
+end
+
+
local function merge_conf(base, new_tab, ppath)
ppath = ppath or ""
@@ -143,12 +161,11 @@ local function merge_conf(base, new_tab, ppath)
if base[key] == nil then
base[key] = val
elseif type(base[key]) ~= type_val then
- if (ppath == "nginx_config" or str_sub(ppath, 1, 14) ==
"nginx_config->") and
- (type_val == "number" or type_val == "string")
- then
+ local path = ppath == "" and key or ppath .. "->" .. key
+
+ if path_is_multi_type(path, type_val) then
base[key] = val
else
- local path = ppath == "" and key or ppath .. "->" .. key
return nil, "failed to merge, path[" .. path .. "]
expect: " ..
type(base[key]) .. ", but got: " .. type_val
end
diff --git a/conf/config-default.yaml b/conf/config-default.yaml
index 352c565..55f3f30 100644
--- a/conf/config-default.yaml
+++ b/conf/config-default.yaml
@@ -20,7 +20,9 @@
#
apisix:
- node_listen: 9080 # APISIX listening port
+ # node_listen: 9080 # APISIX listening port
+ node_listen: # This style support multiple ports
+ - 9080
enable_admin: true
enable_admin_cors: true # Admin API support CORS response headers.
enable_debug: false
diff --git a/t/cli/test_validate_config.sh b/t/cli/test_validate_config.sh
index 529170c..96f6bf2 100755
--- a/t/cli/test_validate_config.sh
+++ b/t/cli/test_validate_config.sh
@@ -69,3 +69,23 @@ fi
make stop
echo "passed: allow configuring address in stream_proxy"
+
+sed -i 's/^ \(node_listen:\)/ #\1/g' conf/config-default.yaml
+sed -i 's/^ \(- 9080\)/ #\1/g' conf/config-default.yaml
+sed -i 's/^ # \(node_listen: 9080\)/ \1/g' conf/config-default.yaml
+
+echo '
+apisix:
+ node_listen:
+ - 9080
+ - 9081
+' > conf/config.yaml
+
+out=$(make init 2>&1 || true)
+if ! echo "$out"; then
+ echo "failed: allow configuring node_listen as a number in the default
config"
+ exit 1
+fi
+git checkout conf/config-default.yaml
+
+echo "passed: allow configuring node_listen as a number in the default config"
diff --git a/t/core/config-default.t b/t/core/config-default.t
index b634e44..17ccedd 100644
--- a/t/core/config-default.t
+++ b/t/core/config-default.t
@@ -44,13 +44,13 @@ admin_key: null
-=== TEST 2: wrong type: expect: number, but got: string
+=== TEST 2: wrong type: expect: table, but got: string
--- yaml_config
apisix:
node_listen: xxxx
--- must_die
--- error_log
-failed to parse yaml config: failed to merge, path[apisix->node_listen]
expect: number, but got: string
+failed to parse yaml config: failed to merge, path[apisix->node_listen]
expect: table, but got: string