Skip to content

Commit

Permalink
chore(plugins) remove deprecated BasePlugin (#7961)
Browse files Browse the repository at this point in the history
* chore(plugins) remove deprecated BasePlugin

It has been removed from the docs for some time, but the core still
has to check each method to see if it's actually reimplemented or just
inherited.

Updated several fixture plugins that still used it.

Co-authored-by: Alan Boudreault <alan@alanb.ca>
  • Loading branch information
javierguerragiraldez and aboudreault committed May 10, 2022
1 parent 23f50ea commit d569af6
Show file tree
Hide file tree
Showing 25 changed files with 79 additions and 377 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ In this release we continued our work on better performance:
Thanks [beldahanit](https://github.com/beldahanit) for reporting the issue!
- Old `BasePlugin` is deprecated and will be removed in a future version of Kong.
Porting tips in the [documentation](https://docs.konghq.com/gateway-oss/2.3.x/plugin-development/custom-logic/#porting-from-old-baseplugin-style)
- The deprecated **BasePlugin** has been removed. [#7961](https://github.com/Kong/kong/pull/7961)

### Fixes

Expand Down Expand Up @@ -904,6 +905,7 @@ grpc-gateway plugin first:

#### Plugins

- All custom plugins that are using the deprecated `BasePlugin` class have to remove this inheritance.
- **LDAP-auth**: The LDAP Authentication schema now includes a default value for the `config.ldap_port` parameter
that matches the documentation. Before the plugin documentation [Parameters](https://docs.konghq.com/hub/kong-inc/ldap-auth/#parameters)
section included a reference to a default value for the LDAP port; however, the default value was not included in the plugin schema.
Expand Down
3 changes: 0 additions & 3 deletions kong-2.8.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ build = {
["kong.resty.dns.client"] = "kong/resty/dns/client.lua",
["kong.resty.dns.utils"] = "kong/resty/dns/utils.lua",
["kong.resty.ctx"] = "kong/resty/ctx.lua",
["kong.vendor.classic"] = "kong/vendor/classic.lua",

["kong.cmd"] = "kong/cmd/init.lua",
["kong.cmd.roar"] = "kong/cmd/roar.lua",
Expand Down Expand Up @@ -256,8 +255,6 @@ build = {
["kong.pdk.cluster"] = "kong/pdk/cluster.lua",
["kong.pdk.vault"] = "kong/pdk/vault.lua",

["kong.plugins.base_plugin"] = "kong/plugins/base_plugin.lua",

["kong.plugins.basic-auth.migrations"] = "kong/plugins/basic-auth/migrations/init.lua",
["kong.plugins.basic-auth.migrations.000_base_basic_auth"] = "kong/plugins/basic-auth/migrations/000_base_basic_auth.lua",
["kong.plugins.basic-auth.migrations.002_130_to_140"] = "kong/plugins/basic-auth/migrations/002_130_to_140.lua",
Expand Down
10 changes: 1 addition & 9 deletions kong/db/dao/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ local constants = require "kong.constants"
local utils = require "kong.tools.utils"
local DAO = require "kong.db.dao"
local plugin_loader = require "kong.db.schema.plugin_loader"
local BasePlugin = require "kong.plugins.base_plugin"
local reports = require "kong.reports"
local plugin_servers = require "kong.runloop.plugin_servers"

Expand Down Expand Up @@ -123,7 +122,7 @@ local function implements(plugin, method)
end

local m = plugin[method]
return type(m) == "function" and m ~= BasePlugin[method]
return type(m) == "function"
end


Expand Down Expand Up @@ -273,13 +272,6 @@ function Plugins:load_plugin_schemas(plugin_set)
local handler, err = load_plugin(self, plugin)

if handler then
if type(handler.is) == "function" and handler:is(BasePlugin) then
-- Backwards-compatibility for 0.x and 1.x plugins inheriting from the
-- BasePlugin class.
-- TODO: deprecate & remove
handler = handler()
end

if handler._go then
go_plugins_cnt = go_plugins_cnt + 1
end
Expand Down
50 changes: 0 additions & 50 deletions kong/plugins/base_plugin.lua

This file was deleted.

18 changes: 6 additions & 12 deletions kong/runloop/plugins_iterator.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local BasePlugin = require "kong.plugins.base_plugin"
local workspaces = require "kong.workspaces"
local constants = require "kong.constants"
local warmup = require "kong.cache.warmup"
Expand Down Expand Up @@ -270,8 +269,7 @@ local function get_next_init_worker(self)

self.i = i

local phase_handler = plugin.handler.init_worker
if phase_handler and phase_handler ~= BasePlugin.init_worker then
if plugin.handler.init_worker then
return plugin
end

Expand Down Expand Up @@ -301,8 +299,7 @@ local function get_next(self)
plugins[0] = n
plugins[n] = cfg
plugins[n-1] = plugin
if not ctx.buffered_proxying and plugin.handler.response and
plugin.handler.response ~= BasePlugin.response then
if not ctx.buffered_proxying and plugin.handler.response then
ctx.buffered_proxying = true
end
end
Expand All @@ -325,10 +322,7 @@ local function get_next_configured_plugin(self)

self.i = i

local phase = self.phase
local phase_handler = plugin.handler[phase]

if phase_handler and phase_handler ~= BasePlugin[phase] then
if plugin.handler[self.phase] then
return plugin, self.plugins[i]
end

Expand Down Expand Up @@ -551,7 +545,8 @@ function PluginsIterator.new(version)

else
if version == "init" and not cache_full then
local ok, err = warmup.single_entity(kong.db.plugins, plugin)
local ok
ok, err = warmup.single_entity(kong.db.plugins, plugin)
if not ok then
if err ~= "no memory" then
return nil, err
Expand Down Expand Up @@ -593,8 +588,7 @@ function PluginsIterator.new(version)
for _, data in pairs(ws) do
for phase_name, phase in pairs(data.phases) do
if data.combos[name] then
local phase_handler = plugin.handler[phase_name]
if phase_handler and phase_handler ~= BasePlugin[phase_name] then
if plugin.handler[phase_name] then
phase[name] = true
end
end
Expand Down
68 changes: 0 additions & 68 deletions kong/vendor/classic.lua

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local function wait()
-- in the logs when executing this
helpers.wait_until(function()
local logs = pl_file.read(TEST_CONF.prefix .. "/" .. TEST_CONF.proxy_error_log)
local _, count = logs:gsub([[executing plugin "logger": log]], "")
local _, count = logs:gsub("%[logger%] log phase", "")

return count >= 1
end, 10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local function wait()
-- in the logs when executing this
helpers.wait_until(function()
local logs = pl_file.read(TEST_CONF.prefix .. "/" .. TEST_CONF.proxy_error_log)
local _, count = logs:gsub([[executing plugin "logger": log]], "")
local _, count = logs:gsub("%[logger%] log phase", "")

return count >= 1
end, 10)
Expand Down
2 changes: 1 addition & 1 deletion spec/02-integration/07-sdk/02-log_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe("PDK: kong.log", function()

local cfg = helpers.test_conf
local logs = pl_file.read(cfg.prefix .. "/" .. cfg.proxy_error_log)
local _, count = logs:gsub([[executing plugin "logger%-last": log]], "")
local _, count = logs:gsub("%[logger%-last%] log phase", "")

return count == 2
end, 10)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
-- a plugin fixture to test a method on the admin api
local BasePlugin = require "kong.plugins.base_plugin"


local AdminApiMethod = BasePlugin:extend()


AdminApiMethod.PRIORITY = 1000


function AdminApiMethod:new()
AdminApiMethod.super.new(self, "admin-api-method")
end

local AdminApiMethod = {
VERSION = "0.1-t",
PRIORITY = 1000,
}

return AdminApiMethod
16 changes: 4 additions & 12 deletions spec/fixtures/custom_plugins/kong/plugins/cache/handler.lua
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
local BasePlugin = require "kong.plugins.base_plugin"
local singletons = require "kong.singletons"


local CacheHandler = BasePlugin:extend()


CacheHandler.PRIORITY = 1000


function CacheHandler:new()
CacheHandler.super.new(self, "cache")
end
local CacheHandler = {
VERSION = "0.1-t",
PRIORITY = 1000,
}


function CacheHandler:access(conf)
CacheHandler.super.access(self)

ngx.req.read_body()

local args, err = ngx.req.get_post_args()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
local BasePlugin = require "kong.plugins.base_plugin"
local CtxCheckerHandler = require "spec.fixtures.custom_plugins.kong.plugins.ctx-checker.handler"


local CtxCheckerLastHandler = BasePlugin:extend()


-- This plugin is a copy of ctx checker with a lower priority (it will run last)
CtxCheckerLastHandler.PRIORITY = 0


function CtxCheckerLastHandler:new()
CtxCheckerLastHandler.super.new(self, "ctx-checker-last")
end
local CtxCheckerLastHandler = {
VERSION = "0.1-t",
PRIORITY = 0,
_name = "ctx-checker-last",
}


CtxCheckerLastHandler.access = CtxCheckerHandler.access
Expand Down
21 changes: 6 additions & 15 deletions spec/fixtures/custom_plugins/kong/plugins/ctx-checker/handler.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local BasePlugin = require "kong.plugins.base_plugin"
local tablex = require "pl.tablex"
local inspect = require "inspect"

Expand All @@ -10,10 +9,11 @@ local error = error
local tostring = tostring


local CtxCheckerHandler = BasePlugin:extend()


CtxCheckerHandler.PRIORITY = 1000
local CtxCheckerHandler = {
VERSION = "0.1-t",
PRIORITY = 1000,
_name = "ctx-checker",
}


local function get_ctx(ctx_kind)
Expand All @@ -39,14 +39,7 @@ local function set_header(conf, name, value)
end


function CtxCheckerHandler:new()
CtxCheckerHandler.super.new(self, "ctx-checker")
end


function CtxCheckerHandler:access(conf)
CtxCheckerHandler.super.access(self)

local set_field = conf.ctx_set_field
if not set_field then
return
Expand Down Expand Up @@ -76,8 +69,6 @@ end


function CtxCheckerHandler:header_filter(conf)
CtxCheckerHandler.super.header_filter(self)

local check_field = conf.ctx_check_field
if not check_field then
return
Expand Down Expand Up @@ -105,7 +96,7 @@ function CtxCheckerHandler:header_filter(conf)
end

if ok then
return set_header(conf, self._name .. "-" .. check_field, tostring(val))
return set_header(conf, self._name .."-" .. check_field, tostring(val))
end

if conf.throw_error then
Expand Down
Loading

0 comments on commit d569af6

Please sign in to comment.