juzhiyuan commented on a change in pull request #2690:
URL: https://github.com/apache/apisix/pull/2690#discussion_r522200494
##########
File path: bin/apisix
##########
@@ -560,6 +560,23 @@ local function init_etcd(show_output)
for index, host in ipairs(yaml_conf.etcd.host) do
local is_success = true
+ local token_head = ""
+ if etcd_conf.user and etcd_conf.password then
+ local uri_auth = host .. "/v3/auth/authenticate"
+ local post_json_auth = '{"name": "' .. etcd_conf.user .. '",
"password": "' .. etcd_conf.password .. '"}'
Review comment:
Could we use some libraries or functions to stringify that object
instead of combining string?
https://stackoverflow.com/questions/24908199/convert-json-string-to-lua-table
##########
File path: bin/apisix
##########
@@ -560,6 +560,23 @@ local function init_etcd(show_output)
for index, host in ipairs(yaml_conf.etcd.host) do
local is_success = true
+ local token_head = ""
+ if etcd_conf.user and etcd_conf.password then
+ local uri_auth = host .. "/v3/auth/authenticate"
+ local post_json_auth = '{"name": "' .. etcd_conf.user .. '",
"password": "' .. etcd_conf.password .. '"}'
Review comment:
According to
https://github.com/apache/apisix/pull/2690/files#diff-0cfc3cc4673fc5c2de7be20b9f8763a8955212292f08a8a7b5d1f459533f5fcdR572
, could we use `dkjson.encode`?
##########
File path: bin/apisix
##########
@@ -560,6 +560,21 @@ local function init_etcd(show_output)
for index, host in ipairs(yaml_conf.etcd.host) do
local is_success = true
+ local token_head = ""
+ if etcd_conf.user and etcd_conf.password then
+ local uri_auth = host .. "/v3/auth/authenticate"
+ local post_json_auth = '{"name": "' .. etcd_conf.user .. '",
"password": "' .. etcd_conf.password .. '"}'
+ local cmd_auth = "curl -s " .. uri_auth .. " -X POST -d '" ..
post_json_auth
+ .. "' --connect-timeout " .. timeout
+ .. " --max-time " .. timeout * 2 .. " --retry 1 2>&1"
+
+ local res_auth = execute_cmd(cmd_auth)
+ local body_auth, _, err_auth = dkjson.decode(res_auth)
+ if not err_auth then
+ token_head = " -H 'Authorization: " .. body_auth.token .. "'"
Review comment:
Agree, once the authentication failed, we have to terminate the command.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]