refactor(rule): rename http_bridge -> webhook

This commit is contained in:
Shawn 2022-05-25 18:56:12 +08:00
parent 71de9616d3
commit a157539710
14 changed files with 47 additions and 49 deletions

View File

@ -28,8 +28,8 @@
# retain = false # retain = false
#} #}
# #
## HTTP bridges to an HTTP server ## WebHook to an HTTP server
#bridges.http.my_http_bridge { #bridges.webhook.my_webhook {
# enable = true # enable = true
# direction = egress # direction = egress
# ## NOTE: we cannot use placehodler variables in the `scheme://host:port` part of the url # ## NOTE: we cannot use placehodler variables in the `scheme://host:port` part of the url

View File

@ -72,14 +72,14 @@ In config files, you can find the corresponding config entry for a connector by
} }
} }
bridges_http { bridges_webhook {
desc { desc {
en: """HTTP bridges to an HTTP server.""" en: """WebHook to an HTTP server."""
zh: """转发消息到 HTTP 服务器的 HTTP Bridge""" zh: """转发消息到 HTTP 服务器的 WebHook"""
} }
label: { label: {
en: "HTTP Bridge" en: "WebHook"
zh: "HTTP Bridge" zh: "WebHook"
} }
} }

View File

@ -1,4 +1,4 @@
emqx_bridge_http_schema { emqx_bridge_webhook_schema {
config_enable { config_enable {
desc { desc {

View File

@ -263,7 +263,7 @@ get_matched_bridges(Topic) ->
(_BName, #{direction := ingress}, Acc1) -> (_BName, #{direction := ingress}, Acc1) ->
Acc1; Acc1;
(BName, #{direction := egress} = Egress, Acc1) -> (BName, #{direction := egress} = Egress, Acc1) ->
%% HTTP, MySQL bridges only have egress direction %% WebHook, MySQL bridges only have egress direction
get_matched_bridge_id(Egress, Topic, BType, BName, Acc1) get_matched_bridge_id(Egress, Topic, BType, BName, Acc1)
end, end,
Acc0, Acc0,

View File

@ -42,8 +42,6 @@
-export([lookup_from_local_node/2]). -export([lookup_from_local_node/2]).
-define(TYPES, [mqtt, http]).
-define(CONN_TYPES, [mqtt]). -define(CONN_TYPES, [mqtt]).
-define(TRY_PARSE_ID(ID, EXPR), -define(TRY_PARSE_ID(ID, EXPR),
@ -148,7 +146,7 @@ param_path_id() ->
#{ #{
in => path, in => path,
required => true, required => true,
example => <<"http:my_http_bridge">>, example => <<"webhook:my_webhook">>,
desc => ?DESC("desc_param_path_id") desc => ?DESC("desc_param_path_id")
} }
)}. )}.
@ -158,9 +156,9 @@ bridge_info_array_example(Method) ->
bridge_info_examples(Method) -> bridge_info_examples(Method) ->
maps:merge(conn_bridge_examples(Method), #{ maps:merge(conn_bridge_examples(Method), #{
<<"http_bridge">> => #{ <<"my_webhook">> => #{
summary => <<"HTTP Bridge">>, summary => <<"WebHook">>,
value => info_example(http, awesome, Method) value => info_example(webhook, awesome, Method)
} }
}). }).
@ -196,7 +194,7 @@ method_example(Type, Direction, Method) when Method == get; Method == post ->
SDir = atom_to_list(Direction), SDir = atom_to_list(Direction),
SName = SName =
case Type of case Type of
http -> "my_" ++ SType ++ "_bridge"; webhook -> "my_" ++ SType;
_ -> "my_" ++ SDir ++ "_" ++ SType ++ "_bridge" _ -> "my_" ++ SDir ++ "_" ++ SType ++ "_bridge"
end, end,
TypeNameExamp = #{ TypeNameExamp = #{
@ -220,7 +218,7 @@ maybe_with_metrics_example(TypeNameExamp, get) ->
maybe_with_metrics_example(TypeNameExamp, _) -> maybe_with_metrics_example(TypeNameExamp, _) ->
TypeNameExamp. TypeNameExamp.
info_example_basic(http, _) -> info_example_basic(webhook, _) ->
#{ #{
enable => true, enable => true,
url => <<"http://localhost:9901/messages/${topic}">>, url => <<"http://localhost:9901/messages/${topic}">>,
@ -232,7 +230,7 @@ info_example_basic(http, _) ->
pool_size => 4, pool_size => 4,
enable_pipelining => true, enable_pipelining => true,
ssl => #{enable => false}, ssl => #{enable => false},
local_topic => <<"emqx_http/#">>, local_topic => <<"emqx_webhook/#">>,
method => post, method => post,
body => <<"${payload}">> body => <<"${payload}">>
}; };

View File

@ -43,8 +43,8 @@
bridge_to_resource_type(<<"mqtt">>) -> emqx_connector_mqtt; bridge_to_resource_type(<<"mqtt">>) -> emqx_connector_mqtt;
bridge_to_resource_type(mqtt) -> emqx_connector_mqtt; bridge_to_resource_type(mqtt) -> emqx_connector_mqtt;
bridge_to_resource_type(<<"http">>) -> emqx_connector_http; bridge_to_resource_type(<<"webhook">>) -> emqx_connector_http;
bridge_to_resource_type(http) -> emqx_connector_http. bridge_to_resource_type(webhook) -> emqx_connector_http.
resource_id(BridgeId) when is_binary(BridgeId) -> resource_id(BridgeId) when is_binary(BridgeId) ->
<<"bridge:", BridgeId/binary>>. <<"bridge:", BridgeId/binary>>.
@ -104,7 +104,7 @@ update(Type, Name, {OldConf, Conf}) ->
%% - if the connection related configs like `servers` is updated, we should restart/start %% - if the connection related configs like `servers` is updated, we should restart/start
%% or stop bridges according to the change. %% or stop bridges according to the change.
%% - if the connection related configs are not update, only non-connection configs like %% - if the connection related configs are not update, only non-connection configs like
%% the `method` or `headers` of a HTTP bridge is changed, then the bridge can be updated %% the `method` or `headers` of a WebHook is changed, then the bridge can be updated
%% without restarting the bridge. %% without restarting the bridge.
%% %%
case if_only_to_toggle_enable(OldConf, Conf) of case if_only_to_toggle_enable(OldConf, Conf) of
@ -237,7 +237,7 @@ is_tmp_path(TmpPath, File) ->
string:str(str(File), str(TmpPath)) > 0. string:str(str(File), str(TmpPath)) > 0.
parse_confs( parse_confs(
http, webhook,
_Name, _Name,
#{ #{
url := Url, url := Url,

View File

@ -46,7 +46,7 @@ http_schema(Method) ->
?CONN_TYPES ?CONN_TYPES
), ),
hoconsc:union([ hoconsc:union([
ref(emqx_bridge_http_schema, Method) ref(emqx_bridge_webhook_schema, Method)
| Schemas | Schemas
]). ]).
@ -108,10 +108,10 @@ roots() -> [bridges].
fields(bridges) -> fields(bridges) ->
[ [
{http, {webhook,
mk( mk(
hoconsc:map(name, ref(emqx_bridge_http_schema, "config")), hoconsc:map(name, ref(emqx_bridge_webhook_schema, "config")),
#{desc => ?DESC("bridges_http")} #{desc => ?DESC("bridges_webhook")}
)} )}
] ++ ] ++
[ [

View File

@ -1,4 +1,4 @@
-module(emqx_bridge_http_schema). -module(emqx_bridge_webhook_schema).
-include_lib("typerefl/include/types.hrl"). -include_lib("typerefl/include/types.hrl").
-include_lib("hocon/include/hoconsc.hrl"). -include_lib("hocon/include/hoconsc.hrl").
@ -81,7 +81,7 @@ fields("get") ->
desc("config") -> desc("config") ->
?DESC("desc_config"); ?DESC("desc_config");
desc(Method) when Method =:= "get"; Method =:= "put"; Method =:= "post" -> desc(Method) when Method =:= "get"; Method =:= "put"; Method =:= "post" ->
["Configuration for HTTP bridge using `", string:to_upper(Method), "` method."]; ["Configuration for WebHook using `", string:to_upper(Method), "` method."];
desc(_) -> desc(_) ->
undefined. undefined.
@ -111,7 +111,7 @@ basic_config() ->
type_field() -> type_field() ->
{type, {type,
mk( mk(
http, webhook,
#{ #{
required => true, required => true,
desc => ?DESC("desc_type") desc => ?DESC("desc_type")

View File

@ -54,8 +54,8 @@ end_per_testcase(t_get_basic_usage_info_1, _Config) ->
{ok, _} = emqx_bridge:remove(BridgeType, BridgeName) {ok, _} = emqx_bridge:remove(BridgeType, BridgeName)
end, end,
[ [
{http, <<"basic_usage_info_http">>}, {webhook, <<"basic_usage_info_webhook">>},
{http, <<"basic_usage_info_http_disabled">>}, {webhook, <<"basic_usage_info_webhook_disabled">>},
{mqtt, <<"basic_usage_info_mqtt">>} {mqtt, <<"basic_usage_info_mqtt">>}
] ]
), ),
@ -81,7 +81,7 @@ t_get_basic_usage_info_1(_Config) ->
#{ #{
num_bridges => 3, num_bridges => 3,
count_by_type => #{ count_by_type => #{
http => 1, webhook => 1,
mqtt => 2 mqtt => 2
} }
}, },
@ -119,7 +119,7 @@ setup_fake_telemetry_data() ->
url => <<"http://localhost:9901/messages/${topic}">>, url => <<"http://localhost:9901/messages/${topic}">>,
enable => true, enable => true,
direction => egress, direction => egress,
local_topic => "emqx_http/#", local_topic => "emqx_webhook/#",
method => post, method => post,
body => <<"${payload}">>, body => <<"${payload}">>,
headers => #{}, headers => #{},
@ -129,10 +129,10 @@ setup_fake_telemetry_data() ->
#{ #{
<<"bridges">> => <<"bridges">> =>
#{ #{
<<"http">> => <<"webhook">> =>
#{ #{
<<"basic_usage_info_http">> => HTTPConfig, <<"basic_usage_info_webhook">> => HTTPConfig,
<<"basic_usage_info_http_disabled">> => <<"basic_usage_info_webhook_disabled">> =>
HTTPConfig#{enable => false} HTTPConfig#{enable => false}
}, },
<<"mqtt">> => <<"mqtt">> =>

View File

@ -23,7 +23,7 @@
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-define(CONF_DEFAULT, <<"bridges: {}">>). -define(CONF_DEFAULT, <<"bridges: {}">>).
-define(BRIDGE_TYPE, <<"http">>). -define(BRIDGE_TYPE, <<"webhook">>).
-define(BRIDGE_NAME, <<"test_bridge">>). -define(BRIDGE_NAME, <<"test_bridge">>).
-define(URL(PORT, PATH), -define(URL(PORT, PATH),
list_to_binary( list_to_binary(
@ -37,7 +37,7 @@
<<"type">> => TYPE, <<"type">> => TYPE,
<<"name">> => NAME, <<"name">> => NAME,
<<"url">> => URL, <<"url">> => URL,
<<"local_topic">> => <<"emqx_http/#">>, <<"local_topic">> => <<"emqx_webhook/#">>,
<<"method">> => <<"post">>, <<"method">> => <<"post">>,
<<"ssl">> => #{<<"enable">> => false}, <<"ssl">> => #{<<"enable">> => false},
<<"body">> => <<"${payload}">>, <<"body">> => <<"${payload}">>,
@ -158,7 +158,7 @@ t_http_crud_apis(_) ->
%% assert we there's no bridges at first %% assert we there's no bridges at first
{ok, 200, <<"[]">>} = request(get, uri(["bridges"]), []), {ok, 200, <<"[]">>} = request(get, uri(["bridges"]), []),
%% then we add a http bridge, using POST %% then we add a webhook bridge, using POST
%% POST /bridges/ will create a bridge %% POST /bridges/ will create a bridge
URL1 = ?URL(Port, "path1"), URL1 = ?URL(Port, "path1"),
{ok, 201, Bridge} = request( {ok, 201, Bridge} = request(
@ -182,7 +182,7 @@ t_http_crud_apis(_) ->
BridgeID = emqx_bridge_resource:bridge_id(?BRIDGE_TYPE, ?BRIDGE_NAME), BridgeID = emqx_bridge_resource:bridge_id(?BRIDGE_TYPE, ?BRIDGE_NAME),
%% send an message to emqx and the message should be forwarded to the HTTP server %% send an message to emqx and the message should be forwarded to the HTTP server
Body = <<"my msg">>, Body = <<"my msg">>,
emqx:publish(emqx_message:make(<<"emqx_http/1">>, Body)), emqx:publish(emqx_message:make(<<"emqx_webhook/1">>, Body)),
?assert( ?assert(
receive receive
{http_server, received, #{ {http_server, received, #{
@ -254,7 +254,7 @@ t_http_crud_apis(_) ->
), ),
%% send an message to emqx again, check the path has been changed %% send an message to emqx again, check the path has been changed
emqx:publish(emqx_message:make(<<"emqx_http/1">>, Body)), emqx:publish(emqx_message:make(<<"emqx_webhook/1">>, Body)),
?assert( ?assert(
receive receive
{http_server, received, #{path := <<"/path2">>}} -> {http_server, received, #{path := <<"/path2">>}} ->

View File

@ -30,7 +30,7 @@
post_request/0 post_request/0
]). ]).
%% the config for http bridges do not need connectors %% the config for webhook bridges do not need connectors
-define(CONN_TYPES, [mqtt]). -define(CONN_TYPES, [mqtt]).
%%====================================================================================== %%======================================================================================

View File

@ -745,8 +745,8 @@ setup_fake_rule_engine_data() ->
[ [
#{function => <<"erlang:hibernate">>, args => #{}}, #{function => <<"erlang:hibernate">>, args => #{}},
#{function => console}, #{function => console},
<<"http:my_http_bridge">>, <<"webhook:my_webhook">>,
<<"http:my_http_bridge">> <<"webhook:my_webhook">>
] ]
} }
), ),
@ -758,7 +758,7 @@ setup_fake_rule_engine_data() ->
actions => actions =>
[ [
<<"mqtt:my_mqtt_bridge">>, <<"mqtt:my_mqtt_bridge">>,
<<"http:my_http_bridge">> <<"webhook:my_webhook">>
] ]
} }
), ),

View File

@ -71,7 +71,7 @@ fields("rules") ->
desc => ?DESC("rules_actions"), desc => ?DESC("rules_actions"),
default => [], default => [],
example => [ example => [
<<"http:my_http_bridge">>, <<"webhook:my_webhook">>,
#{ #{
function => republish, function => republish,
args => #{ args => #{

View File

@ -2274,8 +2274,8 @@ t_get_basic_usage_info_1(_Config) ->
[ [
#{function => <<"erlang:hibernate">>, args => #{}}, #{function => <<"erlang:hibernate">>, args => #{}},
#{function => console}, #{function => console},
<<"http:my_http_bridge">>, <<"webhook:my_webhook">>,
<<"http:my_http_bridge">> <<"webhook:my_webhook">>
] ]
} }
), ),
@ -2287,7 +2287,7 @@ t_get_basic_usage_info_1(_Config) ->
actions => actions =>
[ [
<<"mqtt:my_mqtt_bridge">>, <<"mqtt:my_mqtt_bridge">>,
<<"http:my_http_bridge">> <<"webhook:my_webhook">>
] ]
} }
), ),