fix(emqx_bridge): check if bridge enabled before calling op
This commit is contained in:
parent
a325133391
commit
1bcc5623ed
|
@ -48,6 +48,10 @@
|
||||||
|
|
||||||
-define(BAD_REQUEST(Reason), {400, error_msg('BAD_REQUEST', Reason)}).
|
-define(BAD_REQUEST(Reason), {400, error_msg('BAD_REQUEST', Reason)}).
|
||||||
|
|
||||||
|
-define(BRIDGE_NOT_ENABLED,
|
||||||
|
?BAD_REQUEST(<<"Forbidden operation, bridge not enabled">>)
|
||||||
|
).
|
||||||
|
|
||||||
-define(NOT_FOUND(Reason), {404, error_msg('NOT_FOUND', Reason)}).
|
-define(NOT_FOUND(Reason), {404, error_msg('NOT_FOUND', Reason)}).
|
||||||
|
|
||||||
-define(BRIDGE_NOT_FOUND(BridgeType, BridgeName),
|
-define(BRIDGE_NOT_FOUND(BridgeType, BridgeName),
|
||||||
|
@ -640,8 +644,16 @@ lookup_from_local_node(BridgeType, BridgeName) ->
|
||||||
invalid ->
|
invalid ->
|
||||||
?NOT_FOUND(<<"Invalid operation: ", Op/binary>>);
|
?NOT_FOUND(<<"Invalid operation: ", Op/binary>>);
|
||||||
OperFunc ->
|
OperFunc ->
|
||||||
Nodes = mria:running_nodes(),
|
try is_enabled_bridge(BridgeType, BridgeName) of
|
||||||
call_operation(all, OperFunc, [Nodes, BridgeType, BridgeName])
|
false ->
|
||||||
|
?BRIDGE_NOT_ENABLED;
|
||||||
|
true ->
|
||||||
|
Nodes = mria:running_nodes(),
|
||||||
|
call_operation(all, OperFunc, [Nodes, BridgeType, BridgeName])
|
||||||
|
catch
|
||||||
|
throw:not_found ->
|
||||||
|
?BRIDGE_NOT_FOUND(BridgeType, BridgeName)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
).
|
).
|
||||||
|
|
||||||
|
@ -657,7 +669,7 @@ lookup_from_local_node(BridgeType, BridgeName) ->
|
||||||
OperFunc ->
|
OperFunc ->
|
||||||
try is_enabled_bridge(BridgeType, BridgeName) of
|
try is_enabled_bridge(BridgeType, BridgeName) of
|
||||||
false ->
|
false ->
|
||||||
?BAD_REQUEST(<<"Forbidden operation, bridge not enabled">>);
|
?BRIDGE_NOT_ENABLED;
|
||||||
true ->
|
true ->
|
||||||
case emqx_misc:safe_to_existing_atom(Node, utf8) of
|
case emqx_misc:safe_to_existing_atom(Node, utf8) of
|
||||||
{ok, TargetNode} ->
|
{ok, TargetNode} ->
|
||||||
|
|
|
@ -612,6 +612,7 @@ t_enable_disable_bridges(Config) ->
|
||||||
<<"{\"code\":\"BAD_REQUEST\",\"message\":\"Forbidden operation, bridge not enabled\"}">>,
|
<<"{\"code\":\"BAD_REQUEST\",\"message\":\"Forbidden operation, bridge not enabled\"}">>,
|
||||||
Res
|
Res
|
||||||
),
|
),
|
||||||
|
{ok, 400, Res} = request(post, operation_path(cluster, start, BridgeID), <<"">>),
|
||||||
|
|
||||||
%% enable a stopped bridge
|
%% enable a stopped bridge
|
||||||
{ok, 204, <<>>} = request(put, enable_path(true, BridgeID), <<"">>),
|
{ok, 204, <<>>} = request(put, enable_path(true, BridgeID), <<"">>),
|
||||||
|
|
Loading…
Reference in New Issue