higress-group/higress

Implement api-spec plugin and support api level wasm configuration for all plugins

開放

#601 建立於 2023年10月24日

 (0 則留言) (1 個反應) (0 位負責人)Go (1,219 個分叉)github user discovery
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:

  1. 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.
  1. Config model standards
  • business api: Swagger, OAS3, gRPC/Dubbo IDL etc.
  • route api: Ingress API, Gateway API, etc.
  1. 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:

  1. Apply transform plugin to the pricing api to implement mapping of price fields.
  2. 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 tag and operationId of 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

Other related information

part of https://github.com/alibaba/higress/issues/535

貢獻者指南