Kong 自定义插件管理界面扩展:需要访问插件配置

Kong Custom Plugin Admin Interface extension : need access to config of plugin

我正在构建自定义插件并通过 api.lua

扩展管理界面

函数有 'self' 属性,我可以在其中获取请求信息,但我还需要访问插件配置(例如 handler.lua ).

我该怎么做?

金刚 2.7.0.

return {
    ["/my-route/:id"] = {
        GET = function(self)
        -- do some stuff
        end
    }    
}

谢谢,

彼得

更新

schema.lua

return {
    no_consumer = true, -- this plugin will only be API-wide
    fields = {
        redis_host = { type = "string" },
        redis_port = { type = "number", default = 6379 },
        redis_password = { type = "string" },
        redis_timeout = { type = "number", default = 2000 },
        redis_database = { type = "number", default = 1 }
    }
}

您可以迭代每个插件以按名称获取所有实例

local function each_my_plugin()
  local iter = kong.db.plugins:each()

  return function()
    while true do
      local plugin, err = iter()
      if err then
        return kong.response.exit(500, { message = err })
      end
      if not plugin then
        return
      end
      if plugin.name == "my plugin" then
        return plugin
      end
    end
  end
end

或按 id

kong.db.plugins:select {id = id }