You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sh...@apache.org on 2022/03/01 06:05:31 UTC
[apisix-python-plugin-runner] branch master updated: docs: update developer-guide and getting-started document to 0.2.0 (#44)
This is an automated email from the ASF dual-hosted git repository.
shuaijinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-python-plugin-runner.git
The following commit(s) were added to refs/heads/master by this push:
new 898ada4 docs: update developer-guide and getting-started document to 0.2.0 (#44)
898ada4 is described below
commit 898ada41895c30a9350ec7898094468550e3975d
Author: 帅进超 <sh...@gmail.com>
AuthorDate: Tue Mar 1 14:04:16 2022 +0800
docs: update developer-guide and getting-started document to 0.2.0 (#44)
---
docs/en/latest/developer-guide.md | 67 +++++++++++++++++++++++----------------
docs/en/latest/getting-started.md | 6 ++--
2 files changed, 43 insertions(+), 30 deletions(-)
diff --git a/docs/en/latest/developer-guide.md b/docs/en/latest/developer-guide.md
index d034f0b..9ae5fb4 100644
--- a/docs/en/latest/developer-guide.md
+++ b/docs/en/latest/developer-guide.md
@@ -28,7 +28,7 @@ This documentation explains how to develop this project.
## Prerequisites
* Python 3.7+
-* APISIX 2.7.0
+* APISIX 2.7.0+
## Debug
@@ -56,56 +56,69 @@ the `.py` files in this directory autoload
#### Plugin Format
```python
-from apisix.runner.plugin.base import Base
+from typing import Any
from apisix.runner.http.request import Request
from apisix.runner.http.response import Response
+from apisix.runner.plugin.core import PluginBase
-class Test(Base):
- def __init__(self):
- super(Test, self).__init__(self.__class__.__name__)
+class Test(PluginBase):
- def filter(self, request: Request, response: Response):
+ def name(self) -> str:
+ """
+ The name of the plugin registered in the runner
+ :return:
+ """
+ return "test"
+
+ def config(self, conf: Any) -> Any:
+ """
+ Parse plugin configuration
+ :param conf:
+ :return:
+ """
+ return conf
+
+ def filter(self, conf: Any, request: Request, response: Response):
"""
The plugin executes the main function
+ :param conf:
+ plugin configuration after parsing
:param request:
request parameters and information
:param response:
response parameters and information
:return:
"""
- # Get plugin configuration information through `self.config`
- # print(self.config)
-
- # Setting the request object will continue to forward the request
-
- # Rewrite request headers
- request.headers["X-Resp-A6-Runner"] = "Python"
- # Rewrite request args
- request.args["a6_runner"] = "Python"
+ # print plugin configuration
+ print(conf)
- # Rewrite request path
- request.path = "/a6/python/runner"
+ # Fetch request nginx variable `host`
+ host = request.get_var("host")
+ print(host)
- # Setting the response object will terminate the request and respond to the data
+ # Fetch request body
+ body = request.get_body()
+ print(body)
# Set response headers
- response.headers["X-Resp-A6-Runner"] = "Python"
+ response.set_header("X-Resp-A6-Runner", "Python")
# Set response body
- response.body = "Hello, Python Runner of APISIX"
+ response.set_body("Hello, Python Runner of APISIX")
# Set response status code
- response.status_code = 201
+ response.set_status_code(201)
```
-- The plugin must inherit the `Base` class
-- The plugin must implement the `filter` function
-- `filter` function parameters can only contain `Request` and `Response` classes as parameters
-- Request parameter can get and set request information
-- Response parameter can set response information
-- `self.config` can get plug-in configuration information
+- Plugins must inherit the `PluginBase` class and implement all functions.
+ - `name` function: used to set the registered plugin name.
+ - `config` function: used to parse plugin configuration.
+ - `filter` function: used to filter requests.
+ - `conf` parameter: plugin configuration after parsing.
+ - `request` parameter: Request object, which can be used to get and set request information.
+ - `response` parameter: Response object, which can be used to set response information.
## Test
diff --git a/docs/en/latest/getting-started.md b/docs/en/latest/getting-started.md
index 67dfe76..43f1671 100644
--- a/docs/en/latest/getting-started.md
+++ b/docs/en/latest/getting-started.md
@@ -27,7 +27,7 @@ This document explains how to use Python Runner
## Prerequisites
* Python 3.7+
-* APISIX 2.7.0
+* APISIX 2.7.0+
## Installation
@@ -48,7 +48,7 @@ $ make install
#### Run APISIX Python Runner
```bash
$ cd /path/to/apisix-python-plugin-runner
-$ APISIX_LISTEN_ADDRESS=unix:/tmp/runner.sock python3 bin/py-runner start
+$ make dev
```
#### Modify APISIX configuration file
@@ -74,7 +74,7 @@ apisix:
key: edd1c9f034335f136f87ad84b625c8f1
role: admin
ext-plugin:
- cmd: [ "python3", "/path/to/apisix-python-plugin-runner/apisix/main.py", "start" ]
+ cmd: [ "python3", "/path/to/apisix-python-plugin-runner/bin/py-runner", "start" ]
```
### Log level and socket configuration (Optional)