fix(emqx_bridge): don't crash checking if bridge enabled

This commit is contained in:
Stefan Strigler 2023-03-08 16:33:09 +01:00
parent 80b81748df
commit a325133391
1 changed files with 13 additions and 2 deletions

View File

@ -655,8 +655,7 @@ lookup_from_local_node(BridgeType, BridgeName) ->
invalid ->
?NOT_FOUND(<<"Invalid operation: ", Op/binary>>);
OperFunc ->
ConfMap = emqx:get_config([bridges, BridgeType, BridgeName]),
case maps:get(enable, ConfMap, false) of
try is_enabled_bridge(BridgeType, BridgeName) of
false ->
?BAD_REQUEST(<<"Forbidden operation, bridge not enabled">>);
true ->
@ -668,10 +667,22 @@ lookup_from_local_node(BridgeType, BridgeName) ->
{error, _} ->
?NOT_FOUND(<<"Invalid node name: ", Node/binary>>)
end
catch
throw:not_found ->
?BRIDGE_NOT_FOUND(BridgeType, BridgeName)
end
end
).
is_enabled_bridge(BridgeType, BridgeName) ->
try emqx:get_config([bridges, BridgeType, BridgeName]) of
ConfMap ->
maps:get(enable, ConfMap, false)
catch
error:{config_not_found, _} ->
throw(not_found)
end.
node_operation_func(<<"restart">>) -> restart_bridge_to_node;
node_operation_func(<<"start">>) -> start_bridge_to_node;
node_operation_func(<<"stop">>) -> stop_bridge_to_node;