Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(secret): rectify the way to fetch secret resource by id #11164

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 6 additions & 34 deletions apisix/secret.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ local byte = string.byte
local type = type
local pcall = pcall
local pairs = pairs
local ipairs = ipairs

local _M = {}

Expand All @@ -50,46 +49,19 @@ 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")
if not secret_values or not secret_values.values then
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


Expand Down
Loading