Просмотр исходного кода

fix: the field 'enable' is missing for GET /bridges/:id

Shawn 3 лет назад
Родитель
Сommit
6edb453ce9

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

@@ -648,11 +648,11 @@ fill_defaults(Type, RawConf) ->
     unpack_bridge_conf(Type, FullConf).
 
 pack_bridge_conf(Type, RawConf) ->
-    #{<<"bridges">> => #{Type => #{<<"foo">> => RawConf}}}.
+    #{<<"bridges">> => #{bin(Type) => #{<<"foo">> => RawConf}}}.
 
 unpack_bridge_conf(Type, PackedConf) ->
     #{<<"bridges">> := Bridges} = PackedConf,
-    #{<<"foo">> := RawConf} = maps:get(Type, Bridges),
+    #{<<"foo">> := RawConf} = maps:get(bin(Type), Bridges),
     RawConf.
 
 is_ok(ResL) ->
@@ -689,4 +689,8 @@ error_msg(Code, Msg) ->
     #{code => Code, message => bin(io_lib:format("~p", [Msg]))}.
 
 bin(S) when is_list(S) ->
-    list_to_binary(S).
+    list_to_binary(S);
+bin(S) when is_atom(S) ->
+    atom_to_binary(S, utf8);
+bin(S) when is_binary(S) ->
+    S.

+ 7 - 0
apps/emqx_bridge/test/emqx_bridge_api_SUITE.erl

@@ -171,6 +171,7 @@ t_http_crud_apis(_) ->
     #{
         <<"type">> := ?BRIDGE_TYPE,
         <<"name">> := ?BRIDGE_NAME,
+        <<"enable">> := true,
         <<"status">> := _,
         <<"node_status">> := [_ | _],
         <<"metrics">> := _,
@@ -208,6 +209,7 @@ t_http_crud_apis(_) ->
         #{
             <<"type">> := ?BRIDGE_TYPE,
             <<"name">> := ?BRIDGE_NAME,
+            <<"enable">> := true,
             <<"status">> := _,
             <<"node_status">> := [_ | _],
             <<"metrics">> := _,
@@ -224,6 +226,7 @@ t_http_crud_apis(_) ->
             #{
                 <<"type">> := ?BRIDGE_TYPE,
                 <<"name">> := ?BRIDGE_NAME,
+                <<"enable">> := true,
                 <<"status">> := _,
                 <<"node_status">> := [_ | _],
                 <<"metrics">> := _,
@@ -240,6 +243,7 @@ t_http_crud_apis(_) ->
         #{
             <<"type">> := ?BRIDGE_TYPE,
             <<"name">> := ?BRIDGE_NAME,
+            <<"enable">> := true,
             <<"status">> := _,
             <<"node_status">> := [_ | _],
             <<"metrics">> := _,
@@ -305,6 +309,7 @@ do_start_stop_bridges(Type) ->
     #{
         <<"type">> := ?BRIDGE_TYPE,
         <<"name">> := ?BRIDGE_NAME,
+        <<"enable">> := true,
         <<"status">> := <<"connected">>,
         <<"node_status">> := [_ | _],
         <<"metrics">> := _,
@@ -349,6 +354,7 @@ t_enable_disable_bridges(_) ->
     #{
         <<"type">> := ?BRIDGE_TYPE,
         <<"name">> := ?BRIDGE_NAME,
+        <<"enable">> := true,
         <<"status">> := <<"connected">>,
         <<"node_status">> := [_ | _],
         <<"metrics">> := _,
@@ -397,6 +403,7 @@ t_reset_bridges(_) ->
     #{
         <<"type">> := ?BRIDGE_TYPE,
         <<"name">> := ?BRIDGE_NAME,
+        <<"enable">> := true,
         <<"status">> := <<"connected">>,
         <<"node_status">> := [_ | _],
         <<"metrics">> := _,