This is an automated email from the ASF dual-hosted git repository. sunyi pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 25c5b09 feat: support configure enabled plugin list & sync JSON
Schema (#1513)
25c5b09 is described below
commit 25c5b09ecf73112cde6e944c7721dce56247b94c
Author: nic-chen <[email protected]>
AuthorDate: Thu Feb 25 18:20:12 2021 +0800
feat: support configure enabled plugin list & sync JSON Schema (#1513)
---
.github/workflows/backend-e2e-test.yml | 3 +-
.github/workflows/frontend-e2e-test.yml | 4 +-
api/conf/conf.yaml | 47 +++++
api/conf/schema.json | 296 +++++++++++++++++++++++++++--
api/internal/conf/conf.go | 10 +
api/internal/handler/plugin/plugin.go | 13 +-
api/internal/handler/plugin/plugin_test.go | 18 ++
7 files changed, 370 insertions(+), 21 deletions(-)
diff --git a/.github/workflows/backend-e2e-test.yml
b/.github/workflows/backend-e2e-test.yml
index 1dc62e2..4c91dd6 100644
--- a/.github/workflows/backend-e2e-test.yml
+++ b/.github/workflows/backend-e2e-test.yml
@@ -20,13 +20,14 @@ jobs:
with:
go-version: '1.13'
- - name: Modify conf.yaml Configure for use by the manage-api cluster
+ - name: Modify conf.yaml
run: |
sed -i 's/127.0.0.1:2379/172.16.238.10:2379/' ./api/conf/conf.yaml
sed -i 's/127.0.0.1/0.0.0.0/' ./api/conf/conf.yaml
sed -i '/172.16.238.10:2379/a\ - 172.16.238.11:2379'
./api/conf/conf.yaml
sed -i '/172.16.238.10:2379/a\ - 172.16.238.12:2379'
./api/conf/conf.yaml
sed -i '[email protected]/[email protected]/0@' ./api/conf/conf.yaml
+ sed -i 's@# - dubbo-proxy@- dubbo-proxy@' ./api/conf/conf.yaml
- name: download file Dockerfile-apisix
working-directory: ./api/test/docker
diff --git a/.github/workflows/frontend-e2e-test.yml
b/.github/workflows/frontend-e2e-test.yml
index 654511b..1167d96 100644
--- a/.github/workflows/frontend-e2e-test.yml
+++ b/.github/workflows/frontend-e2e-test.yml
@@ -41,7 +41,9 @@ jobs:
- name: Start manager-api
working-directory: ./api
- run: nohup go run ./cmd/manager &
+ run: |
+ sed -i 's@# - dubbo-proxy@- dubbo-proxy@' ./conf/conf.yaml
+ nohup go run ./cmd/manager &
- name: Install front-end dependencies
run: yarn install
diff --git a/api/conf/conf.yaml b/api/conf/conf.yaml
index 68b1cad..a595de1 100644
--- a/api/conf/conf.yaml
+++ b/api/conf/conf.yaml
@@ -55,3 +55,50 @@ authentication:
password: admin
- username: user
password: user
+
+plugins: # plugin list (sorted in alphabetical order)
+ - api-breaker
+ - authz-keycloak
+ - basic-auth
+ - batch-requests
+ - consumer-restriction
+ - cors
+ # - dubbo-proxy
+ - echo
+ # - error-log-logger
+ # - example-plugin
+ - fault-injection
+ - grpc-transcode
+ - hmac-auth
+ - http-logger
+ - ip-restriction
+ - jwt-auth
+ - kafka-logger
+ - key-auth
+ - limit-conn
+ - limit-count
+ - limit-req
+ # - log-rotate
+ # - node-status
+ - openid-connect
+ - prometheus
+ - proxy-cache
+ - proxy-mirror
+ - proxy-rewrite
+ - redirect
+ - referer-restriction
+ - request-id
+ - request-validation
+ - response-rewrite
+ - serverless-post-function
+ - serverless-pre-function
+ # - skywalking
+ - sls-logger
+ - syslog
+ - tcp-logger
+ - udp-logger
+ - uri-blocker
+ - wolf-rbac
+ - zipkin
+ - server-info
+ - traffic-split
diff --git a/api/conf/schema.json b/api/conf/schema.json
index 345e9a0..200d9f2 100644
--- a/api/conf/schema.json
+++ b/api/conf/schema.json
@@ -78,6 +78,37 @@
"required": ["plugins"],
"type": "object"
},
+ "plugin_config": {
+ "additionalProperties": false,
+ "properties": {
+ "create_time": {
+ "type": "integer"
+ },
+ "desc": {
+ "maxLength": 256,
+ "type": "string"
+ },
+ "id": {
+ "anyOf": [{
+ "maxLength": 64,
+ "minLength": 1,
+ "pattern": "^[a-zA-Z0-9-_.]+$",
+ "type": "string"
+ }, {
+ "minimum": 1,
+ "type": "integer"
+ }]
+ },
+ "plugins": {
+ "type": "object"
+ },
+ "update_time": {
+ "type": "integer"
+ }
+ },
+ "required": ["id", "plugins"],
+ "type": "object"
+ },
"plugins": {
"items": {
"properties": {
@@ -168,6 +199,8 @@
"not": {
"anyOf": [{
"required": ["plugins", "script"]
+ }, {
+ "required": ["plugin_config_id",
"script"]
}]
},
"properties": {
@@ -239,6 +272,17 @@
"minLength": 1,
"type": "string"
},
+ "plugin_config_id": {
+ "anyOf": [{
+ "maxLength": 64,
+ "minLength": 1,
+ "pattern": "^[a-zA-Z0-9-_.]+$",
+ "type": "string"
+ }, {
+ "minimum": 1,
+ "type": "integer"
+ }]
+ },
"plugins": {
"type": "object"
},
@@ -368,7 +412,7 @@
"uniqueItems": true
},
"interval": {
-
"default": 0,
+
"default": 1,
"minimum": 1,
"type": "integer"
},
@@ -435,7 +479,7 @@
"uniqueItems": true
},
"interval": {
-
"default": 0,
+
"default": 1,
"minimum": 1,
"type": "integer"
},
@@ -633,7 +677,7 @@
"enum": ["grpc",
"grpcs", "http", "https"]
},
"service_name": {
- "maxLength": 100,
+ "maxLength": 256,
"minLength": 1,
"type": "string"
},
@@ -798,7 +842,7 @@
"uniqueItems": true
},
"interval": {
-
"default": 0,
+
"default": 1,
"minimum": 1,
"type": "integer"
},
@@ -865,7 +909,7 @@
"uniqueItems": true
},
"interval": {
-
"default": 0,
+
"default": 1,
"minimum": 1,
"type": "integer"
},
@@ -1063,7 +1107,7 @@
"enum": ["grpc",
"grpcs", "http", "https"]
},
"service_name": {
- "maxLength": 100,
+ "maxLength": 256,
"minLength": 1,
"type": "string"
},
@@ -1308,7 +1352,7 @@
"uniqueItems": true
},
"interval": {
-
"default": 0,
+
"default": 1,
"minimum": 1,
"type": "integer"
},
@@ -1375,7 +1419,7 @@
"uniqueItems": true
},
"interval": {
-
"default": 0,
+
"default": 1,
"minimum": 1,
"type": "integer"
},
@@ -1573,7 +1617,7 @@
"enum": ["grpc",
"grpcs", "http", "https"]
},
"service_name": {
- "maxLength": 100,
+ "maxLength": 256,
"minLength": 1,
"type": "string"
},
@@ -1660,7 +1704,7 @@
"uniqueItems": true
},
"interval": {
-
"default": 0,
+
"default": 1,
"minimum": 1,
"type": "integer"
},
@@ -1727,7 +1771,7 @@
"uniqueItems": true
},
"interval": {
-
"default": 0,
+
"default": 1,
"minimum": 1,
"type": "integer"
},
@@ -1925,7 +1969,7 @@
"enum": ["grpc", "grpcs", "http",
"https"]
},
"service_name": {
- "maxLength": 100,
+ "maxLength": 256,
"minLength": 1,
"type": "string"
},
@@ -2336,6 +2380,32 @@
},
"version": 0.1
},
+ "dubbo-proxy": {
+ "priority": 507,
+ "schema": {
+ "$comment": "this is a mark for our injected
plugin schema",
+ "properties": {
+ "disable": {
+ "type": "boolean"
+ },
+ "method": {
+ "minLength": 1,
+ "type": "string"
+ },
+ "service_name": {
+ "minLength": 1,
+ "type": "string"
+ },
+ "service_version": {
+ "pattern":
"^\\d+\\.\\d+\\.\\d+",
+ "type": "string"
+ }
+ },
+ "required": ["service_name", "service_version"],
+ "type": "object"
+ },
+ "version": 0.1
+ },
"echo": {
"priority": 412,
"schema": {
@@ -2379,6 +2449,129 @@
},
"version": 0.1
},
+ "error-log-logger": {
+ "metadata_schema": {
+ "properties": {
+ "batch_max_size": {
+ "default": 1000,
+ "minimum": 0,
+ "type": "integer"
+ },
+ "buffer_duration": {
+ "default": 60,
+ "minimum": 1,
+ "type": "integer"
+ },
+ "host": {
+ "pattern":
"^\\*?[0-9a-zA-Z-._]+$",
+ "type": "string"
+ },
+ "inactive_timeout": {
+ "default": 3,
+ "minimum": 1,
+ "type": "integer"
+ },
+ "keepalive": {
+ "default": 30,
+ "minimum": 1,
+ "type": "integer"
+ },
+ "level": {
+ "default": "WARN",
+ "enum": ["ALERT", "CRIT",
"DEBUG", "EMERG", "ERR", "ERROR", "INFO", "NOTICE", "STDERR", "WARN"],
+ "type": "string"
+ },
+ "max_retry_count": {
+ "default": 0,
+ "minimum": 0,
+ "type": "integer"
+ },
+ "name": {
+ "default": "error-log-logger",
+ "type": "string"
+ },
+ "port": {
+ "minimum": 0,
+ "type": "integer"
+ },
+ "retry_delay": {
+ "default": 1,
+ "minimum": 0,
+ "type": "integer"
+ },
+ "timeout": {
+ "default": 3,
+ "minimum": 1,
+ "type": "integer"
+ },
+ "tls": {
+ "default": false,
+ "type": "boolean"
+ },
+ "tls_server_name": {
+ "type": "string"
+ }
+ },
+ "required": ["host", "port"],
+ "type": "object"
+ },
+ "priority": 1091,
+ "schema": {
+ "$comment": "this is a mark for our injected
plugin schema",
+ "properties": {
+ "disable": {
+ "type": "boolean"
+ }
+ },
+ "type": "object"
+ },
+ "version": 0.1
+ },
+ "example-plugin": {
+ "metadata_schema": {
+ "additionalProperties": false,
+ "properties": {
+ "ikey": {
+ "minimum": 0,
+ "type": "number"
+ },
+ "skey": {
+ "type": "string"
+ }
+ },
+ "required": ["ikey", "skey"],
+ "type": "object"
+ },
+ "priority": 0,
+ "schema": {
+ "$comment": "this is a mark for our injected
plugin schema",
+ "properties": {
+ "disable": {
+ "type": "boolean"
+ },
+ "i": {
+ "minimum": 0,
+ "type": "number"
+ },
+ "ip": {
+ "type": "string"
+ },
+ "port": {
+ "type": "integer"
+ },
+ "s": {
+ "type": "string"
+ },
+ "t": {
+ "minItems": 1,
+ "type": "array"
+ }
+ },
+ "required": ["i"],
+ "type": "object"
+ },
+ "version": 0.1
+ },
"fault-injection": {
"priority": 11000,
"schema": {
@@ -2920,6 +3113,11 @@
"policy": {
"enum":
["redis"]
},
+
"redis_database": {
+
"default": 0,
+
"minimum": 0,
+ "type":
"integer"
+ },
"redis_host": {
"minLength": 2,
"type":
"string"
@@ -3034,6 +3232,20 @@
},
"version": 0.1
},
+ "log-rotate": {
+ "priority": 100,
+ "schema": {
+ "$comment": "this is a mark for our injected
plugin schema",
+ "additionalProperties": false,
+ "properties": {
+ "disable": {
+ "type": "boolean"
+ }
+ },
+ "type": "object"
+ },
+ "version": 0.1
+ },
"mqtt-proxy": {
"priority": 1000,
"schema": {
@@ -3065,6 +3277,20 @@
},
"version": 0.1
},
+ "node-status": {
+ "priority": 1000,
+ "schema": {
+ "$comment": "this is a mark for our injected
plugin schema",
+ "additionalProperties": false,
+ "properties": {
+ "disable": {
+ "type": "boolean"
+ }
+ },
+ "type": "object"
+ },
+ "version": 0.1
+ },
"openid-connect": {
"priority": 2599,
"schema": {
@@ -3514,6 +3740,46 @@
},
"version": 0.1
},
+ "skywalking": {
+ "metadata_schema": {
+ "additionalProperties": false,
+ "properties": {
+ "endpoint_addr": {
+ "default":
"http://127.0.0.1:12800",
+ "type": "string"
+ },
+ "service_instance_name": {
+ "default": "APISIX Instance
Name",
+ "description": "User Service
Instance Name",
+ "type": "string"
+ },
+ "service_name": {
+ "default": "APISIX",
+ "description": "service name
for skywalking",
+ "type": "string"
+ }
+ },
+ "type": "object"
+ },
+ "priority": -1100,
+ "schema": {
+ "$comment": "this is a mark for our injected
plugin schema",
+ "additionalProperties": false,
+ "properties": {
+ "disable": {
+ "type": "boolean"
+ },
+ "sample_ratio": {
+ "default": 1,
+ "maximum": 1,
+ "minimum": 0.00001,
+ "type": "number"
+ }
+ },
+ "type": "object"
+ },
+ "version": 0.1
+ },
"sls-logger": {
"priority": 406,
"schema": {
@@ -3834,7 +4100,7 @@
"uniqueItems": true
},
"interval": {
-
"default": 0,
+
"default": 1,
"minimum": 1,
"type": "integer"
},
@@ -3901,7 +4167,7 @@
"uniqueItems": true
},
"interval": {
-
"default": 0,
+
"default": 1,
"minimum": 1,
"type": "integer"
},
@@ -4099,7 +4365,7 @@
"enum": ["grpc", "grpcs", "http", "https"]
},
"service_name": {
-
"maxLength": 100,
+
"maxLength": 256,
"minLength": 1,
"type": "string"
},
diff --git a/api/internal/conf/conf.go b/api/internal/conf/conf.go
index 4361e2a..ca8c112 100644
--- a/api/internal/conf/conf.go
+++ b/api/internal/conf/conf.go
@@ -55,6 +55,7 @@ var (
ImportSizeLimit = 10 * 1024 * 1024
PIDPath = "/tmp/manager-api.pid"
AllowList []string
+ Plugins = map[string]bool{}
)
type MTLS struct {
@@ -111,6 +112,7 @@ type Authentication struct {
type Config struct {
Conf Conf
Authentication Authentication
+ Plugins []string
}
// TODO: we should no longer use init() function after remove all handler's
integration tests
@@ -187,6 +189,8 @@ func setConf() {
//auth
initAuthentication(config.Authentication)
+
+ initPlugins(config.Plugins)
}
}
@@ -210,6 +214,12 @@ func initAuthentication(conf Authentication) {
}
}
+func initPlugins(plugins []string) {
+ for _, pluginName := range plugins {
+ Plugins[pluginName] = true
+ }
+}
+
func initSchema() {
filePath := WorkDir + "/conf/schema.json"
if schemaContent, err := ioutil.ReadFile(filePath); err != nil {
diff --git a/api/internal/handler/plugin/plugin.go
b/api/internal/handler/plugin/plugin.go
index 5703ede..510b1bc 100644
--- a/api/internal/handler/plugin/plugin.go
+++ b/api/internal/handler/plugin/plugin.go
@@ -73,8 +73,11 @@ func (h *Handler) Plugins(c droplet.Context) (interface{},
error) {
if input.All {
var res []map[string]interface{}
list := plugins.Value().(map[string]interface{})
- for name, conf := range list {
- plugin := conf.(map[string]interface{})
+ for name, config := range list {
+ if res, ok := conf.Plugins[name]; !ok || !res {
+ continue
+ }
+ plugin := config.(map[string]interface{})
plugin["name"] = name
if _, ok := plugin["type"]; !ok {
plugin["type"] = "other"
@@ -87,9 +90,11 @@ func (h *Handler) Plugins(c droplet.Context) (interface{},
error) {
var ret []string
list := plugins.Map()
for pluginName := range list {
- if pluginName != "serverless-post-function" && pluginName !=
"serverless-pre-function" {
- ret = append(ret, pluginName)
+ if res, ok := conf.Plugins[pluginName]; !ok || !res {
+ continue
}
+
+ ret = append(ret, pluginName)
}
return ret, nil
diff --git a/api/internal/handler/plugin/plugin_test.go
b/api/internal/handler/plugin/plugin_test.go
index 58127ba..33afcd7 100644
--- a/api/internal/handler/plugin/plugin_test.go
+++ b/api/internal/handler/plugin/plugin_test.go
@@ -23,6 +23,8 @@ import (
"github.com/shiningrush/droplet"
"github.com/stretchr/testify/assert"
+
+ "github.com/apisix/manager-api/internal/conf"
)
func TestPlugin(t *testing.T) {
@@ -58,7 +60,14 @@ func TestPlugin(t *testing.T) {
basicAuthConsumerSchema = string(consumerSchemaByte)
assert.Nil(t, err)
}
+
+ assert.Contains(t, conf.Plugins, plugin["name"])
}
+
+ assert.Contains(t, conf.Plugins, "server-info")
+ assert.Contains(t, conf.Plugins, "traffic-split")
+ assert.NotContains(t, conf.Plugins, "dubbo-proxy")
+
// plugin type
assert.ElementsMatch(t, []string{"basic-auth", "jwt-auth", "hmac-auth",
"key-auth", "wolf-rbac"}, authPlugins)
// consumer schema
@@ -122,4 +131,13 @@ func TestPlugin(t *testing.T) {
ctx.SetInput(input)
val, _ = handler.Schema(ctx)
assert.NotNil(t, val)
+
+ // schema of dubbo-proxy
+ input = &GetInput{
+ Name: "dubbo-proxy",
+ }
+ ctx.SetInput(input)
+ val, err = handler.Schema(ctx)
+ assert.NotNil(t, val)
+ assert.Nil(t, err)
}
