Kaynağa Gözat

refactor(rule): rename http_bridge -> webhook

Shawn 3 yıl önce
ebeveyn
işleme
a157539710

+ 2 - 2
apps/emqx_bridge/etc/emqx_bridge.conf

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

+ 5 - 5
apps/emqx_bridge/i18n/emqx_bridge_schema.conf

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

+ 1 - 1
apps/emqx_bridge/i18n/emqx_bridge_http_schema.conf

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

+ 1 - 1
apps/emqx_bridge/src/emqx_bridge.erl

@@ -263,7 +263,7 @@ get_matched_bridges(Topic) ->
                     (_BName, #{direction := ingress}, Acc1) ->
                         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)
                 end,
                 Acc0,

+ 7 - 9
apps/emqx_bridge/src/emqx_bridge_api.erl

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

+ 4 - 4
apps/emqx_bridge/src/emqx_bridge_resource.erl

@@ -43,8 +43,8 @@
 
 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(http) -> emqx_connector_http.
+bridge_to_resource_type(<<"webhook">>) -> emqx_connector_http;
+bridge_to_resource_type(webhook) -> emqx_connector_http.
 
 resource_id(BridgeId) when is_binary(BridgeId) ->
     <<"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
     %% or stop bridges according to the change.
     %% - 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.
     %%
     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.
 
 parse_confs(
-    http,
+    webhook,
     _Name,
     #{
         url := Url,

+ 4 - 4
apps/emqx_bridge/src/emqx_bridge_schema.erl

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

+ 3 - 3
apps/emqx_bridge/src/emqx_bridge_http_schema.erl

@@ -1,4 +1,4 @@
--module(emqx_bridge_http_schema).
+-module(emqx_bridge_webhook_schema).
 
 -include_lib("typerefl/include/types.hrl").
 -include_lib("hocon/include/hoconsc.hrl").
@@ -81,7 +81,7 @@ fields("get") ->
 desc("config") ->
     ?DESC("desc_config");
 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(_) ->
     undefined.
 
@@ -111,7 +111,7 @@ basic_config() ->
 type_field() ->
     {type,
         mk(
-            http,
+            webhook,
             #{
                 required => true,
                 desc => ?DESC("desc_type")

+ 7 - 7
apps/emqx_bridge/test/emqx_bridge_SUITE.erl

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

+ 5 - 5
apps/emqx_bridge/test/emqx_bridge_api_SUITE.erl

@@ -23,7 +23,7 @@
 -include_lib("eunit/include/eunit.hrl").
 -include_lib("common_test/include/ct.hrl").
 -define(CONF_DEFAULT, <<"bridges: {}">>).
--define(BRIDGE_TYPE, <<"http">>).
+-define(BRIDGE_TYPE, <<"webhook">>).
 -define(BRIDGE_NAME, <<"test_bridge">>).
 -define(URL(PORT, PATH),
     list_to_binary(
@@ -37,7 +37,7 @@
     <<"type">> => TYPE,
     <<"name">> => NAME,
     <<"url">> => URL,
-    <<"local_topic">> => <<"emqx_http/#">>,
+    <<"local_topic">> => <<"emqx_webhook/#">>,
     <<"method">> => <<"post">>,
     <<"ssl">> => #{<<"enable">> => false},
     <<"body">> => <<"${payload}">>,
@@ -158,7 +158,7 @@ t_http_crud_apis(_) ->
     %% assert we there's no bridges at first
     {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
     URL1 = ?URL(Port, "path1"),
     {ok, 201, Bridge} = request(
@@ -182,7 +182,7 @@ t_http_crud_apis(_) ->
     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
     Body = <<"my msg">>,
-    emqx:publish(emqx_message:make(<<"emqx_http/1">>, Body)),
+    emqx:publish(emqx_message:make(<<"emqx_webhook/1">>, Body)),
     ?assert(
         receive
             {http_server, received, #{
@@ -254,7 +254,7 @@ t_http_crud_apis(_) ->
     ),
 
     %% 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(
         receive
             {http_server, received, #{path := <<"/path2">>}} ->

+ 1 - 1
apps/emqx_connector/src/emqx_connector_schema.erl

@@ -30,7 +30,7 @@
     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]).
 
 %%======================================================================================

+ 3 - 3
apps/emqx_modules/test/emqx_telemetry_SUITE.erl

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

+ 1 - 1
apps/emqx_rule_engine/src/emqx_rule_engine_schema.erl

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

+ 3 - 3
apps/emqx_rule_engine/test/emqx_rule_engine_SUITE.erl

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