Tool to quickly create a plugin with an updated priority.
early development
Kong plugin priorities are static, in source. Occasionally there is a use-case for a different priority setting, in which case the user is advised to create a copy of the original plugin and modify the source.
This utility makes this process a lot easier. It creates a wrapper plugin that takes the original plugin and adjusts the priority.
There are two main uses:
- Executing plugins in a different order
- Running the same plugin functionality twice or more (create indentical plugins with slightly different priorities)
Do NOT upload the generated plugins to LuaRocks since that would pollute the LuaRocks repository with loads of useless/duplicate plugins.
-
Create a wrapper for the 'request-transformer' with priority '999':
./create.sh "request-transformer" 999
New rock is generated:
kong-plugin-request-transformer_999-0.1-1.all.rock
. The new plugin name isrequest-transformer_999
(the old name with the appended new priority) -
Copy the resulting
.rock
file to the target system. Or use the docker tools to inject it into a Kong docker image. -
Install the plugin on your Kong system using LuaRocks
luarocks install kong-plugin-request-transformer_999-0.1-1.all.rock
-
Use your new plugin with Kong (use the NEW name with priority!)
curl -X POST http://kong:8001/plugins \ --data "name=request-transformer_999" \ --data "config.remove.headers=x-toremove, x-another-one"
The utility is a bash
script that uses a docker
build container. Hence only
those are required to run it.
- The plugin does not contain any functional code, but shares everything with
the original:
- if the original code gets updated, the wrapper will use the updated code.
- the new plugin shares the same management API endpoints and data (DAO's).
- There is no performance penalty for using the wrapper.
- One caveat: If a plugin uses its own table to store state (eg. updates
values in
self
), then that is the only part that is NOT shared. Afaik there are currently no such plugins.
Note: the version is the version of the generated wrapper code, and independent of the original code. If the Lua code of the wrapper changes, then also change the version at:
- the generated wrapper in
priority.lua
, theWRAPPER_VERSION
constant - the VERSION in
handler.lua
- Fix: workaround for a LuaJIT bug.
- Fix: fix in version 0.2 was incomplete, the new error could be the existing plugins name, instead of the new name.
- Fix: plugins with
daos.lua
orapi.lua
would fail on more recent versions of Kong because it checks the exact error message.
- Initial version