add rule action and resource

This commit is contained in:
lsxredrain 2021-06-21 15:30:00 +09:00
parent b917314929
commit b32e56089f
3 changed files with 288 additions and 11 deletions

View File

@ -9,6 +9,7 @@ export EMQX_CE_DASHBOARD_VERSION ?= v4.3.0
ifeq ($(OS),Windows_NT)
export REBAR_COLOR=none
endif
ifeq ($(OS),Windows_NT)
GET_DASHBOARD=$(SCRIPTS)/get-windashboard.sh
else
@ -20,6 +21,12 @@ REL_PROFILES := emqx emqx-edge
PKG_PROFILES := emqx-pkg emqx-edge-pkg
PROFILES := $(REL_PROFILES) $(PKG_PROFILES) default
ifeq ($(OS),Windows_NT)
QUIKRUN=$(CURDIR)/_build/$(PROFILE)/rel/emqx/bin/emqx.cmd console
else
QUIKRUN=$(CURDIR)/_build/$(PROFILE)/rel/emqx/bin/emqx console
endif
export REBAR_GIT_CLONE_OPTIONS += --depth=1
.PHONY: default
@ -154,9 +161,5 @@ run: $(PROFILE) quickrun
.PHONY: quickrun
quickrun:
ifeq ($(OS),Windows_NT)
./_build/$(PROFILE)/rel/emqx/bin/emqx.cmd console
else
./_build/$(PROFILE)/rel/emqx/bin/emqx console
endif
@$(QUIKRUN)
include docker.mk

View File

@ -346,6 +346,275 @@
]
}
},
"/actions": {
"get": {
"security": [],
"summary": "获取动作列表",
"description": "获取动作列表",
"parameters": [
],
"responses": {
"200": {
"description": "Returns operation status",
"schema": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/Action"
}
},
"code": {
"type": "number"
}
}
}
},
"400": {
"description": "Bad Request"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"500": {
"description": "Server Internal error"
}
},
"tags": [
"Rule"
]
}
},
"/actions/{id}": {
"get": {
"security": [],
"summary": "获取动作",
"description": "获取动作",
"parameters": [
{
"name": "id",
"in": "path",
"description": "动作名称",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "Returns operation status",
"schema": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/Action"
}
},
"code": {
"type": "number"
}
}
}
},
"400": {
"description": "Bad Request"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"500": {
"description": "Server Internal error"
}
},
"tags": [
"Rule"
]
}
},
"/resources": {
"get": {
"security": [],
"summary": "获取资源列表",
"description": "获取资源列表",
"parameters": [
],
"responses": {
"200": {
"description": "Returns operation status",
"schema": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/Resource"
}
},
"code": {
"type": "number"
}
}
}
},
"400": {
"description": "Bad Request"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"500": {
"description": "Server Internal error"
}
},
"tags": [
"Rule"
]
},
"post": {
"security": [],
"summary": "创建资源",
"description": "创建资源",
"parameters": [
{
"name": "rule",
"in": "body",
"description": "规则引擎配置",
"schema": {
"$ref": "#/definitions/Resource"
}
}
],
"responses": {
"200": {
"description": "Returns operation status"
},
"400": {
"description": "Bad Request"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"500": {
"description": "Server Internal error"
}
},
"tags": [
"Rule"
]
}
},
"/resources/{id}": {
"get": {
"security": [],
"summary": "获取资源",
"description": "获取资源",
"parameters": [
{
"name": "id",
"in": "path",
"description": "资源名称",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "Returns operation status",
"schema": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/Resource"
}
},
"code": {
"type": "number"
}
}
}
},
"400": {
"description": "Bad Request"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"500": {
"description": "Server Internal error"
}
},
"tags": [
"Rule"
]
},
"delete": {
"security": [],
"summary": "删除资源",
"description": "删除资源",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"description": "资源名称",
"type": "string"
}
],
"responses": {
"200": {
"description": "Returns operation status",
"schema": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/Resource"
}
},
"code": {
"type": "number"
}
}
}
},
"400": {
"description": "Bad Request"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"500": {
"description": "Server Internal error"
}
},
"tags": [
"Rule"
]
}
},
"/resource_types": {
"get": {
"security": [],

View File

@ -134,12 +134,18 @@ do_request(get_rules, _Args, _Context, _Req) ->
emqx_rule_engine_api:list_rules(#{}, []);
%% OperationId:get_actions
do_request(get_rule_actions, Args, _Context, _Req) ->
do_request(get_actions, Args, _Context, _Req) ->
?LOG(info, "~p", [Args]),
emqx_rule_engine_api:list_actions(#{}, []);
do_request(get_actions_id, #{<<"id">> := RuleID}, _Context, _Req) ->
emqx_rule_engine_api:show_action(#{id => RuleID}, []);
do_request(get_resources, _Args, _Context, _Req) ->
emqx_rule_engine_api:list_resources(#{}, []);
%% OperationId:post_rule_resource
do_request(post_rule_resource, Params, _Context, _Req) ->
do_request(post_resources, Params, _Context, _Req) ->
?LOG(info, "Params ~p ", [Params]),
Actions = maps:get(<<"actions">>, Params),
?LOG(info, "Actions ~p ", [Actions]),
@ -148,18 +154,17 @@ do_request(post_rule_resource, Params, _Context, _Req) ->
end, Actions),
emqx_rule_engine_api:create_resource(#{}, maps:to_list(Params));
do_request(get_rule_resource_id, #{<<"id">> := ResId}, _Context, _Req) ->
do_request(get_resources_id, #{<<"id">> := ResId}, _Context, _Req) ->
emqx_rule_engine_api:show_resource(#{id => ResId}, []);
do_request(delete_rule_resource_id, #{<<"id">> := Id}, _Context, _Req) ->
do_request(delete_resources_id, #{<<"id">> := Id}, _Context, _Req) ->
emqx_rule_engine_api:delete_resource(#{id => Id}, #{});
do_request(get_resource_types, _Args, _Context, _Req) ->
Resources = dgiot_bridge:get_all_channel(),
{200, Resources};
do_request(get_rule_resource, _Args, _Context, _Req) ->
emqx_rule_engine_api:list_resources(#{}, []);
%% API接口
do_request(_OperationId, _Args, _Context, _Req) ->