Skip to content
Merged
Changes from 1 commit
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: 33 additions & 7 deletions gateway/src/apicast/policy_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ local concat = table.concat
local setmetatable = setmetatable
local pcall = pcall

local tab_new = require('table.new')
local isempty = require('table.isempty')

local manifests_cache = tab_new(32, 0)
Comment thread
tkan145 marked this conversation as resolved.
Outdated

local _M = {}

local resty_env = require('resty.env')
Expand Down Expand Up @@ -70,8 +75,22 @@ local function lua_load_path(load_path)
return format('%s/?.lua', load_path)
end

local function get_manifest(name, version)
Comment thread
tkan145 marked this conversation as resolved.
Outdated
local manifests = manifests_cache[name]
if manifests then
for _, manifest in ipairs(manifests) do
if version == manifest.version then
return manifest
end
end
end
end

local function load_manifest(name, version, path)
local manifest = read_manifest(path)
local manifest = get_manifest(name, version)
if not manifest then
manifest = read_manifest(path)
end

if manifest then
if manifest.version ~= version then
Expand Down Expand Up @@ -110,8 +129,8 @@ end
function _M:load_path(name, version, paths)
local failures = {}

for _, path in ipairs(paths or self.policy_load_paths()) do
local manifest, load_path = load_manifest(name, version, format('%s/%s/%s', path, name, version) )
if version == 'builtin' then
local manifest, load_path = load_manifest(name, version, format('%s/%s', self.builtin_policy_load_path(), name) )

if manifest then
return load_path, manifest.configuration
Expand All @@ -120,8 +139,8 @@ function _M:load_path(name, version, paths)
end
end

if version == 'builtin' then
local manifest, load_path = load_manifest(name, version, format('%s/%s', self.builtin_policy_load_path(), name) )
for _, path in ipairs(paths or self.policy_load_paths()) do
local manifest, load_path = load_manifest(name, version, format('%s/%s/%s', path, name, version) )

if manifest then
return load_path, manifest.configuration
Expand All @@ -130,6 +149,7 @@ function _M:load_path(name, version, paths)
end
end


return nil, nil, failures
end

Expand Down Expand Up @@ -173,9 +193,15 @@ end
-- Returns all the policy modules
function _M:get_all()
local policy_modules = {}
local manifests

local policy_manifests_loader = require('apicast.policy_manifests_loader')
local manifests = policy_manifests_loader.get_all()
if isempty(manifests_cache) then
local policy_manifests_loader = require('apicast.policy_manifests_loader')
manifests = policy_manifests_loader.get_all()
manifests_cache = manifests
else
manifests = manifests_cache
end

for policy_name, policy_manifests in pairs(manifests) do
for _, manifest in ipairs(policy_manifests) do
Expand Down