Bladeren bron

refactor(meta): add data source property for

Signed-off-by: Jiyong Huang <huangjy@emqx.io>
Jiyong Huang 2 jaren geleden
bovenliggende
commit
57da0f70d4

+ 11 - 0
etc/mqtt_source.json

@@ -17,6 +17,17 @@
 		}
 		}
 	},
 	},
 	"libs": [],
 	"libs": [],
+	"dataSource": {
+		"default": "topic1",
+		"hint": {
+			"en_US": "The MQTT topic to subscribe to, e.g. topic1",
+			"zh_CN": "将要订阅的 MQTT 主题, 例如 topic1"
+		},
+		"label": {
+			"en_US": "Data Source (MQTT Topic)",
+			"zh_CN": "数据源(MQTT 主题)"
+		}
+	},
 	"properties": {
 	"properties": {
 		"default": [{
 		"default": [{
 			"name": "connectionSelector",
 			"name": "connectionSelector",

+ 11 - 0
etc/sources/file.json

@@ -17,6 +17,17 @@
     }
     }
   },
   },
   "libs": [],
   "libs": [],
+  "dataSource": {
+    "default": "test.json",
+    "hint": {
+      "en_US": "The file name without directory, e.g. test.json",
+      "zh_CN": "不含路径的文件名,例如 test.json"
+    },
+    "label": {
+      "en_US": "Data Source (File Name)",
+      "zh_CN": "数据源(文件名)"
+    }
+  },
   "properties": {
   "properties": {
     "default": [
     "default": [
       {
       {

+ 10 - 0
etc/sources/httppull.json

@@ -17,6 +17,16 @@
 			"zh_CN": "eKuiper 为提取 HTTP 源流提供了内置支持,该支持可从 HTTP 服务器代理提取消息并输入 eKuiper 处理管道。"
 			"zh_CN": "eKuiper 为提取 HTTP 源流提供了内置支持,该支持可从 HTTP 服务器代理提取消息并输入 eKuiper 处理管道。"
 		}
 		}
 	},
 	},
+	"dataSource": {
+		"hint": {
+			"en_US": "The URL endpoint to concatenate with the URL property to form the complete URL, e.g. /api/data",
+			"zh_CN": "URL 的路径部分,与 URL 属性拼接成最终 URL, 例如 /api/data"
+		},
+		"label": {
+			"en_US": "Data Source (URL Endpoint)",
+			"zh_CN": "数据源(URL拼接路径)"
+		}
+	},
 	"properties": {
 	"properties": {
 		"default": [{
 		"default": [{
 			"name": "url",
 			"name": "url",

+ 11 - 0
etc/sources/httppush.json

@@ -17,6 +17,17 @@
 			"zh_CN": "eKuiper 提供了内置的 HTTP 服务支持,用于接收 HTTP 协议推送的流数据。"
 			"zh_CN": "eKuiper 提供了内置的 HTTP 服务支持,用于接收 HTTP 协议推送的流数据。"
 		}
 		}
 	},
 	},
+	"dataSource": {
+		"default": "/api/data",
+		"hint": {
+			"en_US": "The URL endpoint to append to the http server URL, e.g. /api/data",
+			"zh_CN": "URL 的路径部分,与配置的 HTTP 服务器地址拼接成最终 URL, 例如 /api/data"
+		},
+		"label": {
+			"en_US": "Data Source (URL Endpoint)",
+			"zh_CN": "数据源(URL拼接路径)"
+		}
+	},
 	"properties": {
 	"properties": {
 		"default": [{
 		"default": [{
 			"name": "method",
 			"name": "method",

+ 11 - 0
etc/sources/memory.json

@@ -17,6 +17,17 @@
     }
     }
   },
   },
   "libs": [],
   "libs": [],
+  "dataSource": {
+    "default": "topic1",
+    "hint": {
+      "en_US": "The memory topic to subscribe to, e.g. topic1. It is similar to MQTT topic.",
+      "zh_CN": "将要订阅的内存主题, 例如 topic1。类似 MQTT 主题"
+    },
+    "label": {
+      "en_US": "Data Source (Topic)",
+      "zh_CN": "数据源(主题)"
+    }
+  },
   "properties": {
   "properties": {
   },
   },
   "outputs": [
   "outputs": [

+ 11 - 0
etc/sources/redis.json

@@ -17,6 +17,17 @@
     }
     }
   },
   },
   "libs": [],
   "libs": [],
+  "dataSource": {
+    "default": "0",
+    "hint": {
+      "en_US": "The Redis database to connect to, e.g. 0",
+      "zh_CN": "将要连接的 Redis 数据库号,例如 0"
+    },
+    "label": {
+      "en_US": "Data Source (Database Number)",
+      "zh_CN": "数据源(数据库号)"
+    }
+  },
   "properties": {
   "properties": {
     "default": [
     "default": [
       {
       {

+ 11 - 0
extensions/sources/sql/sql.json

@@ -16,6 +16,17 @@
       "zh_CN": "从数据库中读取消息"
       "zh_CN": "从数据库中读取消息"
     }
     }
   },
   },
+  "dataSource": {
+    "default": "table1",
+    "hint": {
+      "en_US": "The SQL database to connect to, e.g. table1",
+      "zh_CN": "将要连接的关系数据库表,例如 table1"
+    },
+    "label": {
+      "en_US": "Data Source (Table)",
+      "zh_CN": "数据源(表名)"
+    }
+  },
   "libs": [],
   "libs": [],
   "properties": {
   "properties": {
     "default": [
     "default": [

+ 11 - 0
extensions/sources/zmq/zmq.json

@@ -19,6 +19,17 @@
   "libs": [
   "libs": [
     "github.com/pebbe/zmq4@v1.0.0"
     "github.com/pebbe/zmq4@v1.0.0"
   ],
   ],
+  "dataSource": {
+    "default": "topic1",
+    "hint": {
+      "en_US": "The topic to subscribe to, e.g. topic1",
+      "zh_CN": "将要订阅的主题, 例如 topic1"
+    },
+    "label": {
+      "en_US": "Data Source (Topic)",
+      "zh_CN": "数据源(主题)"
+    }
+  },
   "properties": {
   "properties": {
     "default": [
     "default": [
       {
       {

+ 15 - 10
internal/meta/sourceMeta.go

@@ -28,18 +28,20 @@ import (
 
 
 type (
 type (
 	fileSource struct {
 	fileSource struct {
-		About    *fileAbout              `json:"about"`
-		Libs     []string                `json:"libs"`
-		ConfKeys map[string][]*fileField `json:"properties"`
-		Node     interface{}             `json:"node"`
+		About      *fileAbout              `json:"about"`
+		Libs       []string                `json:"libs"`
+		DataSource interface{}             `json:"dataSource,omitempty"`
+		ConfKeys   map[string][]*fileField `json:"properties"`
+		Node       interface{}             `json:"node"`
 	}
 	}
 	uiSource struct {
 	uiSource struct {
-		About    *about             `json:"about"`
-		Libs     []string           `json:"libs"`
-		ConfKeys map[string][]field `json:"properties"`
-		Node     interface{}        `json:"node"`
-		isScan   bool
-		isLookup bool
+		About      *about             `json:"about"`
+		Libs       []string           `json:"libs"`
+		DataSource interface{}        `json:"dataSource,omitempty"`
+		ConfKeys   map[string][]field `json:"properties"`
+		Node       interface{}        `json:"node"`
+		isScan     bool
+		isLookup   bool
 	}
 	}
 )
 )
 
 
@@ -52,6 +54,9 @@ func newUiSource(fi *fileSource, isScan bool, isLookup bool) (*uiSource, error)
 	ui.Libs = fi.Libs
 	ui.Libs = fi.Libs
 	ui.About = newAbout(fi.About)
 	ui.About = newAbout(fi.About)
 	ui.Node = fi.Node
 	ui.Node = fi.Node
+	if fi.DataSource != nil {
+		ui.DataSource = fi.DataSource
+	}
 	ui.ConfKeys = make(map[string][]field)
 	ui.ConfKeys = make(map[string][]field)
 	for k, fields := range fi.ConfKeys {
 	for k, fields := range fi.ConfKeys {
 		if ui.ConfKeys[k], err = newField(fields); nil != err {
 		if ui.ConfKeys[k], err = newField(fields); nil != err {

+ 4 - 0
internal/meta/sourceMeta_test.go

@@ -37,6 +37,10 @@ func TestGetMqttSourceMeta(t *testing.T) {
 		t.Error(err)
 		t.Error(err)
 	}
 	}
 
 
+	if showMeta.DataSource == nil {
+		t.Errorf("mqtt source meta data source is null")
+	}
+
 	fields := showMeta.ConfKeys["default"]
 	fields := showMeta.ConfKeys["default"]
 
 
 	if len(fields) == 0 {
 	if len(fields) == 0 {