shreemaan-abhishek commented on code in PR #11080:
URL: https://github.com/apache/apisix/pull/11080#discussion_r1553983796


##########
apisix/core/id.lua:
##########
@@ -20,17 +20,23 @@
 -- @module core.id
 
 local fetch_local_conf = require("apisix.core.config_local").local_conf
-local try_read_attr    = require("apisix.core.table").try_read_attr
-local log              = require("apisix.core.log")
-local uuid             = require('resty.jit-uuid')
-local smatch           = string.match
-local open             = io.open
-
-
+local try_read_attr = require("apisix.core.table").try_read_attr
+local profile = require("apisix.core.profile")
+local log = require("apisix.core.log")
+local uuid = require("resty.jit-uuid")
+local lyaml = require("lyaml")
+local smatch = string.match
+local open = io.open
+local type = type
+local ipairs = ipairs
+local string = string
+local math = math
 local prefix = ngx.config.prefix()
 local apisix_uid
+local pairs = pairs
+local ngx_exit = ngx.exit
 
-local _M = {version = 0.1}
+local _M = { version = 0.1 }

Review Comment:
   please revert this change.



##########
t/fuzzing/simple_http.py:
##########
@@ -41,10 +49,18 @@ def create_route():
         }
     })
     conn = connect_admin()
+    key = get_admin_key_from_yaml('conf/config.yaml')
+    if key is None:
+        print("Key not found in the YAML file.")
+        return
+    key = key.replace('"', '')
+    print("the key is",key)

Review Comment:
   ```suggestion
       print("the key is", key)
   ```



##########
apisix/core/id.lua:
##########
@@ -20,17 +20,23 @@
 -- @module core.id
 
 local fetch_local_conf = require("apisix.core.config_local").local_conf
-local try_read_attr    = require("apisix.core.table").try_read_attr
-local log              = require("apisix.core.log")
-local uuid             = require('resty.jit-uuid')
-local smatch           = string.match
-local open             = io.open
-
-
+local try_read_attr = require("apisix.core.table").try_read_attr

Review Comment:
   please maintain code beautification (equals on top of each other)



##########
.github/workflows/source-install.yml:
##########
@@ -88,8 +88,15 @@ jobs:
 
       - name: Test apisix
         run: |
-          curl http://127.0.0.1:9180/apisix/admin/routes/1 \
-            -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+            wget 
https://github.com/mikefarah/yq/releases/download/3.4.1/yq_linux_amd64 -O 
/usr/bin/yq && sudo chmod +x /usr/bin/yq

Review Comment:
   this block has 4 indents, where as everywhere in this file there are 2 
indents.



##########
apisix/core/id.lua:
##########
@@ -61,19 +63,88 @@ local function write_file(path, data)
     return true
 end
 
+local function generate_yaml(table)
+    -- By default lyaml will parse null values as []
+    -- The following logic is a workaround so that null values are parsed as 
null
+    local function replace_null(tbl)
+        for k, v in pairs(tbl) do
+            if type(v) == "table" then
+                replace_null(v)
+            elseif v == nil then
+                tbl[k] = "<PLACEHOLDER>"
+            end
+        end
+    end
+
+    -- Replace null values with "<PLACEHOLDER>"
+    replace_null(table)
+
+    -- Convert Lua table to YAML string without parsing null values
+    local yaml = lyaml.dump({ table }, { no_nil = true })
+
+    -- Replace "<PLACEHOLDER>" with null except for empty arrays
+    yaml = yaml:gsub("<PLACEHOLDER>", "null"):gsub("%[%s*%]", "null")
+
+    -- Ensure boolean values remain intact
+    yaml = yaml:gsub(":%s*true%s*true", ": true"):gsub(":%s*false%s*true", ": 
false")
+
+    -- Replace *no_nil with true
+    yaml = yaml:gsub("&no_nil", "true")
+
+    -- Remove any occurrences of *no_nil
+    yaml = yaml:gsub(":%s*%*no_nil", ": true")
+
+    -- Remove duplicates for boolean values
+    yaml = yaml:gsub("true%s*true", "true"):gsub("false%s*false", "false")
+
+    return yaml
+end
+
 
 _M.gen_uuid_v4 = uuid.generate_v4
 
+--- This will autogenerate the admin key if it's passed as an empty string in 
the configuration.
+local function autogenerate_admin_key(default_conf)
+    local changed = false
+    -- Check if deployment.admin.admin_key is not nil and it's an array
+    local admin_keys = default_conf.deployment
+        and default_conf.deployment.admin
+        and default_conf.deployment.admin.admin_key
+    if admin_keys and type(admin_keys) == "table" then
+        for i, admin_key in ipairs(admin_keys) do
+            if admin_key.role == "admin" and admin_key.key == "" then
+                changed = true
+                admin_keys[i].key = ""
+                for _ = 1, 32 do
+                    admin_keys[i].key = admin_keys[i].key ..
+                    string.char(math.random(65, 90) + math.random(0, 1) * 32)
+                end

Review Comment:
   @Revolyssup please address these comments.



##########
conf/config-default.yaml:
##########
@@ -170,7 +170,8 @@ nginx_config:                     # Config for render the 
template to generate n
   stream:
     enable_access_log: false                 # Enable stream proxy access 
logging.
     access_log: logs/access_stream.log       # Location of the stream access 
log.
-    access_log_format: "$remote_addr [$time_local] $protocol $status 
$bytes_sent $bytes_received $session_time" # Customize log format: 
http://nginx.org/en/docs/varindex.html
+    access_log_format: |
+      "$remote_addr [$time_local] $protocol $status $bytes_sent 
$bytes_received $session_time" # Customize log format: 
http://nginx.org/en/docs/varindex.html

Review Comment:
   @Revolyssup please address this comment.



##########
.github/workflows/source-install.yml:
##########
@@ -99,15 +106,15 @@ jobs:
                   }
               }
             }'
-          result_code=`curl -I -m 10 -o /dev/null -s -w %{http_code} 
http://127.0.0.1:9080/get`
-          if [[ $result_code -ne 200 ]]; then
-              printf "result_code: %s\n" "$result_code"
-              echo "===============access.log==============="
-              cat logs/access.log
-              echo "===============error.log==============="
-              cat logs/error.log
-              exit 125
-          fi
+            result_code=`curl -I -m 10 -o /dev/null -s -w %{http_code} 
http://127.0.0.1:9080/get`

Review Comment:
   this change is not needed.



-- 
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.

To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to