docs: improve plugin-develop docs#12242
Conversation
|
Please resolve lint errors. |
| ## Where to put your plugins | ||
|
|
||
| There are two ways to add new features based on APISIX. | ||
| Setup the `extra_lua_path` in `conf/config.yaml` to load your own code (or `extra_lua_cpath` for compiled .so or .dll file). |
There was a problem hiding this comment.
| Setup the `extra_lua_path` in `conf/config.yaml` to load your own code (or `extra_lua_cpath` for compiled .so or .dll file). | |
| Use the `extra_lua_path` parameter in `conf/config.yaml` file to load your custom plugin code (or use `extra_lua_cpath` for compiled `.so` or `.dll` file). |
| │ └── apisix | ||
| │ ├── plugins | ||
| │ │ └── 3rd-party.lua | ||
| │ └── stream |
There was a problem hiding this comment.
Maybe leave the stream and mention in text that if you would like to load a custom stream (L4) plugin, this is how it should structured. My concern is that once the stream folder is removed, it is not documented anywhere else.
There was a problem hiding this comment.
I know nothing about the stream folder, please revise this section yourself.
| :::note | ||
|
|
||
| If you need to customize the directory of plugin, please create a subdirectory of `/apisix/plugins` under this directory. | ||
| The directory (`/path/to/example`) must contain the `/apisix/plugins` subdirectory. |
There was a problem hiding this comment.
How about
| The directory (`/path/to/example`) must contain the `/apisix/plugins` subdirectory. | |
| The directory (`/path/to/example`) must contain the `/apisix/plugins` subdirectory for L7 plugins. |
|
|
||
| if you have dependencies on external libraries, check the dependent items. if your plugin needs to use shared memory, it | ||
| needs to declare via [customizing Nginx configuration](./customize-nginx-configuration.md), for example : | ||
| Once the plugins configuration is defined in `conf/config.yaml`, the new plugins list will replace the default configuration instead of merging. Therefore, when defining the `plugins` field, make sure to include the built-in plugins that are being used. To maintain consistency with the default behavior, you can include all the default enabled plugins defined in **apisix/cli/config.lua**. |
There was a problem hiding this comment.
| Once the plugins configuration is defined in `conf/config.yaml`, the new plugins list will replace the default configuration instead of merging. Therefore, when defining the `plugins` field, make sure to include the built-in plugins that are being used. To maintain consistency with the default behavior, you can include all the default enabled plugins defined in **apisix/cli/config.lua**. | |
| Once the plugins configuration is defined in `conf/config.yaml`, the new plugins list will replace the default configuration instead of merging. Therefore, when defining the `plugins` field, make sure to include the built-in plugins that are being used. To maintain consistency with the default behavior, you can include all the default enabled plugins defined in `apisix/cli/config.lua`. |
| method "http_init" in the file __apisix/init.lua__, and you may need to add some processing on generated part of Nginx | ||
| configuration file in __apisix/cli/ngx_tpl.lua__ file. But it is easy to have an impact on the overall situation according to the | ||
| existing plugin mechanism, **we do not recommend this unless you have a complete grasp of the code**. | ||
| The [example-plugin](https://github.com/apache/apisix/blob/master/apisix/plugins/example-plugin.lua) plugin (local location: **apisix/plugins/example-plugin.lua**) provides an example. |
There was a problem hiding this comment.
| The [example-plugin](https://github.com/apache/apisix/blob/master/apisix/plugins/example-plugin.lua) plugin (local location: **apisix/plugins/example-plugin.lua**) provides an example. | |
| The [`example-plugin`](https://github.com/apache/apisix/blob/master/apisix/plugins/example-plugin.lua) plugin in this repo provides an example. |
|
|
||
| ## Check external dependencies | ||
|
|
||
| If you have dependencies on external libraries, check the dependent items. if your plugin needs to use shared memory, it |
There was a problem hiding this comment.
| If you have dependencies on external libraries, check the dependent items. if your plugin needs to use shared memory, it | |
| If you have dependencies on external libraries, check the dependent items. If your plugin needs to use shared memory, it |
| Parameters can be stored encrypted by specifying `encrypt_fields = {"password"}` in the `schema`. APISIX will provide the following functionality. | ||
|
|
||
| - When adding and updating resources via the `Admin API`, APISIX automatically encrypts the parameters declared in `encrypt_fields` and stores them in etcd | ||
| - When fetching resources via the `Admin API` and when running the plugin, APISIX automatically decrypts the parameters declared in `encrypt_fields` |
|
|
||
| ::: note | ||
| APISIX version is not less than 3.1 | ||
| ::: |
There was a problem hiding this comment.
|
|
||
| How to enable this feature? | ||
|
|
||
| Enable `data_encryption` in `config.yaml`. |
|
|
||
| Note : if the dependency of some plugin needs to be initialized when Nginx start, you may need to add logic to the initialization | ||
| method "http_init" in the file __apisix/init.lua__, and you may need to add some processing on generated part of Nginx | ||
| configuration file in __apisix/cli/ngx_tpl.lua__ file. But it is easy to have an impact on the overall situation according to the |
There was a problem hiding this comment.
Put the paths above in inline code, instead of bolding them?
| In addition, if the plugin needs to use some metadata, we can define the plugin `metadata_schema`, and then we can dynamically manage these metadata through the `Admin API`. Example: | ||
| ::: | ||
|
|
||
| The input parameter **schema_type** is used to distinguish between different schemas types. For example, many plugins need to use some [metadata](./terminology/plugin-metadata.md), so they define the plugin's `metadata_schema`. Another example, the [key-auth](https://github.com/apache/apisix/blob/master/apisix/plugins/key-auth.lua) plugin needs to provide a `consumer_schema` to check the configuration of the `plugins` attribute of the `consumer` resource in order to be used with the [Consumer](./admin-api.md#consumer) resource. |
There was a problem hiding this comment.
For the reader, the purpose of this paragraph is simply to indicate that the function can be used to check different schemas, so I removed the excessive content, including consumer_schema. However, consumer_schema might still be worth keeping.
I have reorganized this paragraph.
kayx23
left a comment
There was a problem hiding this comment.
Just this comment and there are a few previous comments that were not addressed. See https://github.com/apache/apisix/pull/12242/files Other changes look good
| To validate the configuration, the plugin uses a schema like this: | ||
| Another example, the [key-auth](https://github.com/apache/apisix/blob/master/apisix/plugins/key-auth.lua) plugin needs to provide a `consumer_schema` to check the configuration of the `plugins` attribute of the `consumer` resource in order to be used with the [Consumer](./admin-api.md#consumer) resource. | ||
|
|
||
| ```lua |
There was a problem hiding this comment.
The missing parts have been adddressed.
Except for the stream plugin part(including the descriptions of L4 and L7). Since I can only find related content in the blogs, I thought it's better that the maintainers provide detailed content for this part.





Description
I encountered some difficulties while following the plugin-develop documentation during development:
Therefore, I restructured the overall layout, provided more detailed explanations in some sections, and added some relevant resources.
Which issue(s) this PR fixes:
Fixes #
Checklist