higress-group/higress
Implement api-spec plugin and support api level wasm configuration for all plugins
开放
#601 创建于 2023年10月24日
area/apimarea/pluginhelp wantedlevel/challengesig/apim
仓库指标
- 星标
- (9,036 个星标)
- PR 合并指标
- (平均合并 7天 9小时) (30 天内合并 18 个 PR)
描述
Why do you need it?
The api we are talking about here is "business api".
There are several differences between business api and route api:
- Intent
business api: Use to specific business functions such as trading, pricing, etc.route api: Used to determine which service to proxy the request to if it meets certain conditions.
- Config model standards
business api: Swagger, OAS3, gRPC/Dubbo IDL etc.route api: Ingress API, Gateway API, etc.
- Granularity
business api: One business function is mapped to one api.route api: One service backend is mapped to some apis.
We want to implement business api level strategy, for example:
- Apply transform plugin to the pricing api to implement mapping of price fields.
- Apply key-rate-limit plugin to the trading api to limit transactions per second per user.
How could it be?
- Implement a plugin which can binding business apis to a route (or service in the feature), plugin's configuration maybe like:
apiVersion: extensions.higress.io/v1alpha1
kind: WasmPlugin
metadata:
name: api-spec
namespace: higress-system
spec:
url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/api-spec:1.0.0
matchRules:
- ingress:
- default/foo
config:
name: petStore
basePath: /v1
spec:
'/pet/{petId}':
get:
tags:
- pet
operationId: getPetById
post:
tags:
- pet
operationId: updatePetWithForm
- We can control the acl of operationId of router
apiVersion: extensions.higress.io/v1alpha1
kind: WasmPlugin
metadata:
name: api-acl
namespace: higress-system
spec:
url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/api-acl:1.0.0
matchRules:
- ingress:
- default/foo
config:
allow:
- getPetById
# deny:
# - updatePetWithForm
- We can enable additional plugins when matching API's
tagandoperationIdof specific routes:
apiVersion: extensions.higress.io/v1alpha1
kind: WasmPlugin
metadata:
name: request-transform
namespace: higress-system
spec:
url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/transformer:1.0.0
matchRules:
- api:
- updatePetWithForm
ingress:
- default/foo
config:
type: request
rules:
- operate: map
querys:
- key: petId
value: petid
- apiTag:
- pet
ingress:
- default/foo
config:
type: request
rules:
- operate: remove
headers:
- key: x-test-id