From 4bdbdff157152f938b30760a8f761d499d744efa Mon Sep 17 00:00:00 2001 From: Zhefeng Chen Date: Mon, 2 Sep 2024 15:57:14 +0800 Subject: [PATCH] feat(runloop): added the workspace id into the plugin config in the plugins iterator the workspace id is needed in some cases, for example in the configure handler. https://konghq.atlassian.net/browse/FTI-6200 --- changelog/unreleased/kong/feat-plugin-conf-ws-id.yml | 3 +++ kong/runloop/plugins_iterator.lua | 1 + spec/02-integration/07-sdk/04-plugin-config_spec.lua | 2 ++ 3 files changed, 6 insertions(+) create mode 100644 changelog/unreleased/kong/feat-plugin-conf-ws-id.yml diff --git a/changelog/unreleased/kong/feat-plugin-conf-ws-id.yml b/changelog/unreleased/kong/feat-plugin-conf-ws-id.yml new file mode 100644 index 0000000000000..06ab3da5da3db --- /dev/null +++ b/changelog/unreleased/kong/feat-plugin-conf-ws-id.yml @@ -0,0 +1,3 @@ +message: Added the workspace id into the plugin config in the plugins iterator. +type: feature +scope: Core diff --git a/kong/runloop/plugins_iterator.lua b/kong/runloop/plugins_iterator.lua index 78a6421011a60..ea0325b02d5b7 100644 --- a/kong/runloop/plugins_iterator.lua +++ b/kong/runloop/plugins_iterator.lua @@ -161,6 +161,7 @@ local function get_plugin_config(plugin, name, ws_id) cfg.consumer_id = plugin.consumer and plugin.consumer.id cfg.plugin_instance_name = plugin.instance_name cfg.__plugin_id = plugin.id + cfg.__ws_id = ws_id local key = kong.db.plugins:cache_key(name, cfg.route_id, diff --git a/spec/02-integration/07-sdk/04-plugin-config_spec.lua b/spec/02-integration/07-sdk/04-plugin-config_spec.lua index b56e98e731122..7dac75fd2b5a2 100644 --- a/spec/02-integration/07-sdk/04-plugin-config_spec.lua +++ b/spec/02-integration/07-sdk/04-plugin-config_spec.lua @@ -4,6 +4,7 @@ local cjson = require "cjson" describe("Plugin configuration", function() local proxy_client + local default_ws_id = workspaces.get_workspace().id lazy_setup(function() local bp = helpers.get_db_utils(nil, { @@ -49,5 +50,6 @@ describe("Plugin configuration", function() local body = assert.status(200, res) local json = cjson.decode(body) assert.equal("test", json.plugin_instance_name) + assert.equal(kong.default_workspace, json.__ws_id) end) end)