fix: when enable is false, restart and stop cannot be performed.
This commit is contained in:
parent
0a16c9fabf
commit
eb3870b538
|
@ -334,7 +334,9 @@ schema("/nodes/:node/bridges/:id/operation/:operation") ->
|
|||
],
|
||||
responses => #{
|
||||
200 => <<"Operation success">>,
|
||||
400 => error_schema('INVALID_ID', "Bad bridge ID")
|
||||
400 => error_schema('INVALID_ID', "Bad bridge ID"),
|
||||
403 => error_schema('FORBIDDEN_REQUEST', "forbidden operation")
|
||||
|
||||
}
|
||||
}
|
||||
}.
|
||||
|
@ -428,11 +430,16 @@ lookup_from_local_node(BridgeType, BridgeName) ->
|
|||
?TRY_PARSE_ID(Id, case operation_func(Op) of
|
||||
invalid -> {400, error_msg('BAD_REQUEST', <<"invalid operation">>)};
|
||||
OperFunc when OperFunc == restart; OperFunc == stop ->
|
||||
ConfMap = emqx:get_config([bridges, BridgeType, BridgeName]),
|
||||
case maps:get(enable, ConfMap, false) of
|
||||
false -> {403, error_msg('FORBIDDEN_REQUEST', <<"forbidden operation">>)};
|
||||
true ->
|
||||
case emqx_bridge:OperFunc(BridgeType, BridgeName) of
|
||||
ok -> {200};
|
||||
{error, Reason} ->
|
||||
{500, error_msg('INTERNAL_ERROR', Reason)}
|
||||
end
|
||||
end
|
||||
end).
|
||||
|
||||
operation_func(<<"stop">>) -> stop;
|
||||
|
|
|
@ -324,6 +324,10 @@ t_enable_disable_bridges(_) ->
|
|||
}, jsx:decode(Bridge3)),
|
||||
%% disable it again
|
||||
{ok, 200, <<>>} = request(post, operation_path(cluster, disable, BridgeID), <<"">>),
|
||||
|
||||
{ok, 403, Res} = request(post, operation_path(node, restart, BridgeID), <<"">>),
|
||||
?assertEqual(<<"{\"code\":\"FORBIDDEN_REQUEST\",\"message\":\"forbidden operation\"}">>, Res),
|
||||
|
||||
%% enable a stopped bridge
|
||||
{ok, 200, <<>>} = request(post, operation_path(cluster, enable, BridgeID), <<"">>),
|
||||
{ok, 200, Bridge4} = request(get, uri(["bridges", BridgeID]), []),
|
||||
|
|
Loading…
Reference in New Issue