Monday, January 2, 2023

Kong plugin - Modules required

In its purest form, a plugin consists of two mandatory modules:

simple-plugin

├── handler.lua

└── schema.lua

handler.lua: the core of your plugin. It is an interface to implement, in which each function will be run at the desired moment in the lifecycle of a request / connection.

schema.lua: your plugin probably has to retain some configuration entered by the user. This module holds the schema of that configuration and defines rules on it, so that the user can only enter valid configuration values

Advanced plugin modules

Some plugins might have to integrate deeper with Kong: have their own table in the database, expose endpoints in the Admin API, etc. Each of those can be done by adding a new module to your plugin. Here is what the structure of a plugin would look like if it was implementing all of the optional modules:


complete-plugin

├── api.lua

├── daos.lua

├── handler.lua

├── migrations

│   ├── init.lua

│   └── 000_base_complete_plugin.lua

└── schema.lua


Below is a possible full list of modules 


MODULE NAME REQUIRED DESCRIPTION

admin-api.lua No Defines a list of endpoints to be available in the Admin API to interact with the custom entities handled by your plugin.

daos.lua No Defines a list of DAOs (Database Access Objects) that are abstractions of custom entities needed by your plugin and stored in the data store.

handler.lua Yes An interface to implement. Each function is to be run by Kong at the desired moment in the lifecycle of a request / connection.

migrations/*.lua No The database migrations (e.g. creation of tables). Migrations are only necessary when your plugin has to store custom entities in the database and interact with them through one of the DAOs defined by daos.lua.

schema.lua Yes Holds the schema of your plugin’s configuration, so that the user can only enter valid configuration values.

references:

https://docs.konghq.com/gateway/latest/plugin-development/file-structure/


No comments:

Post a Comment