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 => #{
|
responses => #{
|
||||||
200 => <<"Operation success">>,
|
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
|
?TRY_PARSE_ID(Id, case operation_func(Op) of
|
||||||
invalid -> {400, error_msg('BAD_REQUEST', <<"invalid operation">>)};
|
invalid -> {400, error_msg('BAD_REQUEST', <<"invalid operation">>)};
|
||||||
OperFunc when OperFunc == restart; OperFunc == stop ->
|
OperFunc when OperFunc == restart; OperFunc == stop ->
|
||||||
case emqx_bridge:OperFunc(BridgeType, BridgeName) of
|
ConfMap = emqx:get_config([bridges, BridgeType, BridgeName]),
|
||||||
ok -> {200};
|
case maps:get(enable, ConfMap, false) of
|
||||||
{error, Reason} ->
|
false -> {403, error_msg('FORBIDDEN_REQUEST', <<"forbidden operation">>)};
|
||||||
{500, error_msg('INTERNAL_ERROR', Reason)}
|
true ->
|
||||||
end
|
case emqx_bridge:OperFunc(BridgeType, BridgeName) of
|
||||||
|
ok -> {200};
|
||||||
|
{error, Reason} ->
|
||||||
|
{500, error_msg('INTERNAL_ERROR', Reason)}
|
||||||
|
end
|
||||||
|
end
|
||||||
end).
|
end).
|
||||||
|
|
||||||
operation_func(<<"stop">>) -> stop;
|
operation_func(<<"stop">>) -> stop;
|
||||||
|
|
|
@ -324,6 +324,10 @@ t_enable_disable_bridges(_) ->
|
||||||
}, jsx:decode(Bridge3)),
|
}, jsx:decode(Bridge3)),
|
||||||
%% disable it again
|
%% disable it again
|
||||||
{ok, 200, <<>>} = request(post, operation_path(cluster, disable, BridgeID), <<"">>),
|
{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
|
%% enable a stopped bridge
|
||||||
{ok, 200, <<>>} = request(post, operation_path(cluster, enable, BridgeID), <<"">>),
|
{ok, 200, <<>>} = request(post, operation_path(cluster, enable, BridgeID), <<"">>),
|
||||||
{ok, 200, Bridge4} = request(get, uri(["bridges", BridgeID]), []),
|
{ok, 200, Bridge4} = request(get, uri(["bridges", BridgeID]), []),
|
||||||
|
|
Loading…
Reference in New Issue