Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update global-rule/plugin-config/plugin/ docs #8262

Merged
merged 9 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/en/latest/terminology/global-rule.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
---
title: Global Rule
title: Global Rules
keywords:
- API gateway
- Apache APISIX
- Global Rules
description: This article describes how to use global rules.
---

<!--
Expand All @@ -25,6 +30,8 @@ title: Global Rule

A [Plugin](./plugin.md) configuration can be bound directly to a [Route](./route.md), a [Service](./service.md) or a [Consumer](./consumer.md). But what if we want a Plugin to work on all requests? This is where we register a global Plugin with Global Rule.

Compared with the plugin configuration in Route, Service, Plugin Config, and Consumer, the plugin in the Global Rules is always executed first.

## Example

The example below shows how you can use the `limit-count` Plugin on all requests:
Expand Down
79 changes: 49 additions & 30 deletions docs/en/latest/terminology/plugin-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,60 @@ description: Plugin Config in Apache APISIX.
#
-->

## Description

Plugin Configs are used to extract commonly used [Plugin](./plugin.md) configurations and can be bound directly to a [Route](./route.md).

While configuring the same plugin, only one copy of the configuration is valid. The order of precedence is always `Consumer` > `Consumer Group` > `Route` > `plugin_config` > `Service`.

## Example

The example below illustrates how to create a Plugin Config and bind it to a Route:

```shell
curl http://127.0.0.1:9180/apisix/admin/plugin_configs/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"desc": "blah",
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503
```shell
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add some spaces here? 😄

curl http://127.0.0.1:9180/apisix/admin/plugin_configs/1 \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"desc": "blah",
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503
}
}
}
}'
```
}'
```

```shell
curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"uris": ["/index.html"],
"plugin_config_id": 1,
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
```shell
curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"uris": ["/index.html"],
"plugin_config_id": 1,
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
}
}
}'
```
}'
```

When APISIX can't find the Plugin Config with the `id`, the requests reaching this Route are terminated with a status code of 503.
When APISIX can't find the Plugin Config with the `id`, the requests reaching this Route are terminated with a status code of `503`.

If a Route already has the `plugins` field configured, the plugins in the Plugin Config will effectively be merged to it. The same plugin in the Plugin Config will not override the ones configured directly in the Route.
:::note

For example, if we configure a Plugin Config as shown below
If a Route already has the `plugins` field configured, the plugins in the Plugin Config will effectively be merged to it.

```
The same plugin in the Plugin Config will not override the ones configured directly in the Route. For more information, see [Plugin](./plugin.md).

:::

For example, if you configure a Plugin Config as shown below:

```shell
curl http://127.0.0.1:9180/apisix/admin/plugin_configs/1 \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"desc": "I am plugin_config 1",
"plugins": {
Expand All @@ -85,7 +100,9 @@ For example, if we configure a Plugin Config as shown below

to a Route as shown below,

```
```shell
curl http://127.0.0.1:9180/apisix/admin/routes/1 \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"uris": ["/index.html"],
"plugin_config_id": 1,
Expand All @@ -112,7 +129,9 @@ to a Route as shown below,

the effective configuration will be as the one shown below:

```
```shell
curl http://127.0.0.1:9180/apisix/admin/routes/1 \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"uris": ["/index.html"],
"upstream": {
Expand Down
25 changes: 17 additions & 8 deletions docs/en/latest/terminology/plugin.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
---
title: Plugin
keywords:
- API Gateway
- Apache APISIX
- Plugin
- Filter
- Priority
description: This article introduces the related information of the APISIX Plugin object and how to use it, and introduces how to customize the plugin priority, customize the error response, and dynamically control the execution status of the plugin.
---

<!--
Expand All @@ -25,13 +32,15 @@ title: Plugin

This represents the configuration of the plugins that are executed during the HTTP request/response lifecycle. A **Plugin** configuration can be bound directly to a [`Route`](./route.md), a [`Service`](./service.md), a [`Consumer`](./consumer.md) or a [`Plugin Config`](./plugin-config.md).

You can also refer to [Admin API](../admin-api.md#plugin) for how to use this resource.

:::note

While configuring the same plugin, only one copy of the configuration is valid. The order of precedence is always `Consumer` > `Consumer Group` > `Route` > `plugin_config` > `Service`.

:::

While [configuring APISIX](./architecture-design/apisix.md#configuring-apisix), you can declare the Plugins that are supported by the local APISIX node. This acts as a whitelisting mechanism as Plugins that are not in this whitelist will be automatically ignored. So, this feature can be used to temporarily turn off/turn on specific plugins.
While configuring APISIX, you can declare the Plugins that are supported by the local APISIX node. This acts as a whitelisting mechanism as Plugins that are not in this whitelist will be automatically ignored. So, this feature can be used to temporarily turn off/turn on specific plugins.

## Adding a Plugin

Expand Down Expand Up @@ -78,12 +87,12 @@ ip-restriction exits with http status code 403

Some common configurations can be applied to plugins through the `_meta` configuration items, the specific configuration items are as follows:

| Name | Type | Description |
|--------------|------|-------------|
| disable | boolean | Whether to disable the plugin |
| error_response | string/object | Custom error response |
| priority | integer | Custom plugin priority |
| filter | array | Depending on the requested parameters, it is decided at runtime whether the plugin should be executed. Something like this: `{{var, operator, val}, {var, operator, val}, ...}}`. For example: `{"arg_version", "==", "v2"}`, indicating that the current request parameter `version` is `v2`. The variables here are consistent with NGINX internal variables. For details on supported operators, please see [lua-resty-expr](https://github.com/api7/lua-resty-expr#operator-list). |
| Name | Type | Description |
|----------------|--------------- |-------------|
| disable | boolean | When set to `true`, the plugin is disabled. |
| error_response | string/object | Custom error response. |
| priority | integer | Custom plugin priority. |
| filter | array | Depending on the requested parameters, it is decided at runtime whether the plugin should be executed. Something like this: `{{var, operator, val}, {var, operator, val}, ...}}`. For example: `{"arg_version", "==", "v2"}`, indicating that the current request parameter `version` is `v2`. The variables here are consistent with NGINX internal variables. For details on supported operators, please see [lua-resty-expr](https://github.com/api7/lua-resty-expr#operator-list). |

### Disable the plugin

Expand All @@ -103,7 +112,7 @@ Through the `disable` configuration, you can add a new plugin with disabled stat

Through the `error_response` configuration, you can configure the error response of any plugin to a fixed value to avoid troubles caused by the built-in error response information of the plugin.

The configuration below means to customize the error response of the `jwt-auth` plugin to '{"message": "Missing credential in request"}'.
The configuration below means to customize the error response of the `jwt-auth` plugin to `Missing credential in request`.

```json
{
Expand Down
30 changes: 21 additions & 9 deletions docs/zh/latest/terminology/global-rule.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
---
title: Global rule
title: Global rules
keywords:
- API 网关
- Apache APISIX
- Global Rules
- 全局规则
description: 本文介绍了全局规则的概念以及如何启用全局规则。
---

<!--
Expand All @@ -21,12 +27,20 @@ title: Global rule
#
-->

[Plugin](plugin.md) 配置可直接绑定在 [Route](route.md) 上,也可以被绑定在 [Service](service.md) 或 [Consumer](consumer.md) 上,如果我们需要一个能作用于所有请求的 [Plugin](plugin.md) 该怎么办呢?
这时候我们可以使用 `GlobalRule` 来注册一个全局的 [Plugin](plugin.md):
## 描述

[Plugin](plugin.md) 配置可直接绑定在 [Route](route.md) 上,也可以被绑定在 [Service](service.md) 或 [Consumer](consumer.md) 上。

如果你需要一个能作用于所有请求的 Plugin,可以通过 Global Rules 启用一个全局的插件配置。

全局规则相对于 Route、Service、Plugin Config、Consumer 中的插件配置,Global Rules 中的插件总是优先执行。

## 使用示例

以下示例展示了如何为所有请求启用 `limit-count` 插件:

```shell
curl -X PUT \
https://{apisix_listen_address}/apisix/admin/global_rules/1 \
curl https://127.0.0.1:9180/apisix/admin/global_rules/1 -X PUT \
-H 'Content-Type: application/json' \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
-d '{
Expand All @@ -42,10 +56,8 @@ curl -X PUT \
}'
```

如上所注册的 `limit-count` 插件将会作用于所有的请求。

我们可以通过以下接口查看所有的 `GlobalRule`:
你也可以通过以下命令查看所有的全局规则:

```shell
curl https://{apisix_listen_address}/apisix/admin/global_rules -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'
curl https://127.0.0.1:9180/apisix/admin/global_rules -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'
```
Loading