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(BRIDGE_NOT_ENABLED,
|
||||
?BAD_REQUEST(<<"Forbidden operation, bridge not enabled">>)
|
||||
).
|
||||
|
||||
-define(NOT_FOUND(Reason), {404, error_msg('NOT_FOUND', Reason)}).
|
||||
|
||||
-define(BRIDGE_NOT_FOUND(BridgeType, BridgeName),
|
||||
|
@ -640,8 +644,16 @@ lookup_from_local_node(BridgeType, BridgeName) ->
|
|||
invalid ->
|
||||
?NOT_FOUND(<<"Invalid operation: ", Op/binary>>);
|
||||
OperFunc ->
|
||||
Nodes = mria:running_nodes(),
|
||||
call_operation(all, OperFunc, [Nodes, BridgeType, BridgeName])
|
||||
try is_enabled_bridge(BridgeType, BridgeName) of
|
||||
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
|
||||
).
|
||||
|
||||
|
@ -657,7 +669,7 @@ lookup_from_local_node(BridgeType, BridgeName) ->
|
|||
OperFunc ->
|
||||
try is_enabled_bridge(BridgeType, BridgeName) of
|
||||
false ->
|
||||
?BAD_REQUEST(<<"Forbidden operation, bridge not enabled">>);
|
||||
?BRIDGE_NOT_ENABLED;
|
||||
true ->
|
||||
case emqx_misc:safe_to_existing_atom(Node, utf8) of
|
||||
{ok, TargetNode} ->
|
||||
|
|
|
@ -612,6 +612,7 @@ t_enable_disable_bridges(Config) ->
|
|||
<<"{\"code\":\"BAD_REQUEST\",\"message\":\"Forbidden operation, bridge not enabled\"}">>,
|
||||
Res
|
||||
),
|
||||
{ok, 400, Res} = request(post, operation_path(cluster, start, BridgeID), <<"">>),
|
||||
|
||||
%% enable a stopped bridge
|
||||
{ok, 204, <<>>} = request(put, enable_path(true, BridgeID), <<"">>),
|
||||
|
|
Loading…
Reference in New Issue