membphis commented on a change in pull request #2092:
URL: https://github.com/apache/apisix/pull/2092#discussion_r486965508



##########
File path: bin/apisix
##########
@@ -637,6 +637,45 @@ local function read_yaml_conf()
         merge_conf(default_conf, user_conf)
     end
 
+    -- check the Admin API token
+    if default_conf.apisix.enable_admin then
+        local help = [[
+ERROR: missing valid apisix.admin_key
+
+Needs to set Admin API key in file `conf/config.yaml` . Here is an example:
+
+#############################
+apisix:
+    admin_key:
+        -
+            name: "admin"
+            key:          # <-- replace with your Admin Key
+            role: admin
+#############################
+
+Then you can use it to access Admin API.
+eg: $ curl -i http://127.0.0.1:]] .. default_conf.apisix.node_listen .. 
[[/apisix/admin/routes/1 -H 'X-API-KEY: YOUR-KEY'
+]]
+        if type(default_conf.apisix.admin_key) ~= "table" or
+           #default_conf.apisix.admin_key == 0
+        then
+            io.stderr:write(help, "\n")
+            os.exit(1)
+        end
+
+        for _, admin in ipairs(default_conf.apisix.admin_key) do
+            if type(admin.key) == "table" then
+                admin.key = ""
+            else
+                admin.key = tostring(admin.key)
+            end
+
+            if admin.key == "" or admin.key:gsub("*", "") == "" then

Review comment:
       ```shell
   $ ./bin/apisix start
   ERROR: missing valid apisix.admin_key
   
   You can call `./bin/apisix gen_admin_key` to generate a new Admin API key or
   manually update the `conf/config.yaml` file.
   
   $ ./bin/apisix gen_admin_key
   generate admin key successfully
   
   $ ./bin/apisix start
   
   $ ps -ef | grep apisix
   resty     551863       1  0 06:45 ?        00:00:00 nginx: master process 
openresty -p /home/resty/git/membphis/apisix -c 
/home/resty/git/membphis/apisix/conf/nginx.conf
   resty     552021  253872  0 06:46 pts/0    00:00:00 grep --color=auto 
--exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg 
--exclude-dir=.svn apisix

##########
File path: bin/apisix
##########
@@ -637,6 +637,45 @@ local function read_yaml_conf()
         merge_conf(default_conf, user_conf)
     end
 
+    -- check the Admin API token
+    if default_conf.apisix.enable_admin then
+        local help = [[
+ERROR: missing valid apisix.admin_key
+
+Needs to set Admin API key in file `conf/config.yaml` . Here is an example:
+
+#############################
+apisix:
+    admin_key:
+        -
+            name: "admin"
+            key:          # <-- replace with your Admin Key
+            role: admin
+#############################
+
+Then you can use it to access Admin API.
+eg: $ curl -i http://127.0.0.1:]] .. default_conf.apisix.node_listen .. 
[[/apisix/admin/routes/1 -H 'X-API-KEY: YOUR-KEY'
+]]
+        if type(default_conf.apisix.admin_key) ~= "table" or
+           #default_conf.apisix.admin_key == 0
+        then
+            io.stderr:write(help, "\n")
+            os.exit(1)
+        end
+
+        for _, admin in ipairs(default_conf.apisix.admin_key) do
+            if type(admin.key) == "table" then
+                admin.key = ""
+            else
+                admin.key = tostring(admin.key)
+            end
+
+            if admin.key == "" or admin.key:gsub("*", "") == "" then

Review comment:
       the user needs to call `apisix gen_admin_key` if missing a valid Admin 
API key.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to