This is an automated email from the ASF dual-hosted git repository.
shreemaanabhishek 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 77258c4fb fix(secret): rectify the way to fetch secret resource by id
(#11164)
77258c4fb is described below
commit 77258c4fb4b15ec194cb9adb33b23314ace4b696
Author: Abhishek Choudhary <[email protected]>
AuthorDate: Thu Apr 25 19:02:50 2024 +0545
fix(secret): rectify the way to fetch secret resource by id (#11164)
---
apisix/secret.lua | 40 ++++++----------------------------------
1 file changed, 6 insertions(+), 34 deletions(-)
diff --git a/apisix/secret.lua b/apisix/secret.lua
index 90a99d321..6ba02768d 100644
--- a/apisix/secret.lua
+++ b/apisix/secret.lua
@@ -26,7 +26,6 @@ local byte = string.byte
local type = type
local pcall = pcall
local pairs = pairs
-local ipairs = ipairs
local _M = {}
@@ -50,36 +49,6 @@ local function check_secret(conf)
end
-local secret_kv_lrucache = core.lrucache.new({
- ttl = 300, count = 512
-})
-
-local function create_secret_kvs(values)
- local secret_managers = {}
-
- for _, v in ipairs(values) do
- if v then
- local path = v.value.id
- local idx = find(path, "/")
- if not idx then
- core.log.error("no secret id")
- return nil
- end
-
- local manager = sub(path, 1, idx - 1)
- local id = sub(path, idx + 1)
-
- if not secret_managers[manager] then
- secret_managers[manager] = {}
- end
- secret_managers[manager][id] = v.value
- end
- end
-
- return secret_managers
-end
-
-
local function secret_kv(manager, confid)
local secret_values
secret_values = core.config.fetch_created_obj("/secrets")
@@ -87,9 +56,12 @@ end
return nil
end
- local secret_managers = secret_kv_lrucache("secret_kv",
secret_values.conf_version,
- create_secret_kvs, secret_values.values)
- return secret_managers[manager] and secret_managers[manager][confid]
+ local secret = secret_values:get(manager .. "/" .. confid)
+ if not secret then
+ return nil
+ end
+
+ return secret.value
end