|
@@ -481,8 +481,7 @@ schema("/bridges_probe") ->
|
|
|
?BAD_REQUEST('ALREADY_EXISTS', <<"bridge already exists">>);
|
|
?BAD_REQUEST('ALREADY_EXISTS', <<"bridge already exists">>);
|
|
|
{error, not_found} ->
|
|
{error, not_found} ->
|
|
|
Conf = filter_out_request_body(Conf0),
|
|
Conf = filter_out_request_body(Conf0),
|
|
|
- {ok, _} = emqx_bridge:create(BridgeType, BridgeName, Conf),
|
|
|
|
|
- lookup_from_all_nodes(BridgeType, BridgeName, 201)
|
|
|
|
|
|
|
+ create_bridge(BridgeType, BridgeName, Conf)
|
|
|
end;
|
|
end;
|
|
|
'/bridges'(get, _Params) ->
|
|
'/bridges'(get, _Params) ->
|
|
|
Nodes = mria:running_nodes(),
|
|
Nodes = mria:running_nodes(),
|
|
@@ -508,8 +507,7 @@ schema("/bridges_probe") ->
|
|
|
{ok, _} ->
|
|
{ok, _} ->
|
|
|
RawConf = emqx:get_raw_config([bridges, BridgeType, BridgeName], #{}),
|
|
RawConf = emqx:get_raw_config([bridges, BridgeType, BridgeName], #{}),
|
|
|
Conf = deobfuscate(Conf1, RawConf),
|
|
Conf = deobfuscate(Conf1, RawConf),
|
|
|
- {ok, _} = emqx_bridge:create(BridgeType, BridgeName, Conf),
|
|
|
|
|
- lookup_from_all_nodes(BridgeType, BridgeName, 200);
|
|
|
|
|
|
|
+ update_bridge(BridgeType, BridgeName, Conf);
|
|
|
{error, not_found} ->
|
|
{error, not_found} ->
|
|
|
?BRIDGE_NOT_FOUND(BridgeType, BridgeName)
|
|
?BRIDGE_NOT_FOUND(BridgeType, BridgeName)
|
|
|
end
|
|
end
|
|
@@ -609,6 +607,20 @@ lookup_from_local_node(BridgeType, BridgeName) ->
|
|
|
Error -> Error
|
|
Error -> Error
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
|
|
+create_bridge(BridgeType, BridgeName, Conf) ->
|
|
|
|
|
+ create_or_update_bridge(BridgeType, BridgeName, Conf, 201).
|
|
|
|
|
+
|
|
|
|
|
+update_bridge(BridgeType, BridgeName, Conf) ->
|
|
|
|
|
+ create_or_update_bridge(BridgeType, BridgeName, Conf, 200).
|
|
|
|
|
+
|
|
|
|
|
+create_or_update_bridge(BridgeType, BridgeName, Conf, HttpStatusCode) ->
|
|
|
|
|
+ case emqx_bridge:create(BridgeType, BridgeName, Conf) of
|
|
|
|
|
+ {ok, _} ->
|
|
|
|
|
+ lookup_from_all_nodes(BridgeType, BridgeName, HttpStatusCode);
|
|
|
|
|
+ {error, #{kind := validation_error} = Reason} ->
|
|
|
|
|
+ ?BAD_REQUEST(map_to_json(Reason))
|
|
|
|
|
+ end.
|
|
|
|
|
+
|
|
|
'/bridges/:id/enable/:enable'(put, #{bindings := #{id := Id, enable := Enable}}) ->
|
|
'/bridges/:id/enable/:enable'(put, #{bindings := #{id := Id, enable := Enable}}) ->
|
|
|
?TRY_PARSE_ID(
|
|
?TRY_PARSE_ID(
|
|
|
Id,
|
|
Id,
|
|
@@ -1033,3 +1045,8 @@ deobfuscate(NewConf, OldConf) ->
|
|
|
#{},
|
|
#{},
|
|
|
NewConf
|
|
NewConf
|
|
|
).
|
|
).
|
|
|
|
|
+
|
|
|
|
|
+map_to_json(M) ->
|
|
|
|
|
+ emqx_json:encode(
|
|
|
|
|
+ emqx_map_lib:jsonable_map(M, fun(K, V) -> {K, emqx_map_lib:binary_string(V)} end)
|
|
|
|
|
+ ).
|