Преглед изворни кода

Merge pull request #8758 from emqx/fix-listener-bind-fmt

chore: bind option support `:1883` style config
JianBo He пре 3 година
родитељ
комит
8b4d4f6a69
3 измењених фајлова са 17 додато и 5 уклоњено
  1. 1 0
      CHANGES-5.0.md
  2. 4 0
      apps/emqx/src/emqx_schema.erl
  3. 12 5
      apps/emqx_management/src/emqx_mgmt_api_listeners.erl

+ 1 - 0
CHANGES-5.0.md

@@ -13,6 +13,7 @@
 * Updated `/nodes` API node_status from `Running/Stopped` to `running/stopped`. [#8642](https://github.com/emqx/emqx/pull/8642)
 * Improve handling of placeholder interpolation errors [#8635](https://github.com/emqx/emqx/pull/8635)
 * Better logging on unknown object IDs. [#8670](https://github.com/emqx/emqx/pull/8670)
+* The bind option support `:1883` style. [#8758](https://github.com/emqx/emqx/pull/8758)
 
 # 5.0.4
 

+ 4 - 0
apps/emqx/src/emqx_schema.erl

@@ -2162,8 +2162,12 @@ to_bar_separated_list(Str) ->
 %%  - 127.0.0.1:1883
 %%  - ::1:1883
 %%  - [::1]:1883
+%%  - :1883
+%%  - :::1883
 to_ip_port(Str) ->
     case split_ip_port(Str) of
+        {"", Port} ->
+            {ok, {{0, 0, 0, 0}, list_to_integer(Port)}};
         {Ip, Port} ->
             PortVal = list_to_integer(Port),
             case inet:parse_address(Ip) of

+ 12 - 5
apps/emqx_management/src/emqx_mgmt_api_listeners.erl

@@ -342,11 +342,18 @@ list_listeners(get, #{query_string := Query}) ->
     {200, listener_status_by_id(NodeL)}.
 
 crud_listeners_by_id(get, #{bindings := #{id := Id0}}) ->
-    Listeners = [
-        Conf#{<<"id">> => Id, <<"type">> => Type}
-     || {Id, Type, Conf} <- emqx_listeners:list_raw(),
-        Id =:= Id0
-    ],
+    Listeners =
+        [
+            Conf#{
+                <<"id">> => Id,
+                <<"type">> => Type,
+                <<"bind">> := iolist_to_binary(
+                    emqx_listeners:format_bind(maps:get(<<"bind">>, Conf))
+                )
+            }
+         || {Id, Type, Conf} <- emqx_listeners:list_raw(),
+            Id =:= Id0
+        ],
     case Listeners of
         [] -> {404, #{code => 'BAD_LISTENER_ID', message => ?LISTENER_NOT_FOUND}};
         [L] -> {200, L}