fix: fix newly found unsafe `binary_to_atom`
This commit is contained in:
parent
f44e70a026
commit
19405114e2
|
@ -62,8 +62,15 @@ bridge_id(BridgeType, BridgeName) ->
|
|||
-spec parse_bridge_id(list() | binary() | atom()) -> {atom(), binary()}.
|
||||
parse_bridge_id(BridgeId) ->
|
||||
case string:split(bin(BridgeId), ":", all) of
|
||||
[Type, Name] -> {binary_to_atom(Type, utf8), Name};
|
||||
_ -> error({invalid_bridge_id, BridgeId})
|
||||
[Type, Name] ->
|
||||
case emqx_misc:safe_to_existing_atom(Type, utf8) of
|
||||
{ok, Type1} ->
|
||||
{Type1, Name};
|
||||
_ ->
|
||||
error({invalid_bridge_id, BridgeId})
|
||||
end;
|
||||
_ ->
|
||||
error({invalid_bridge_id, BridgeId})
|
||||
end.
|
||||
|
||||
reset_metrics(ResourceId) ->
|
||||
|
|
|
@ -121,13 +121,21 @@ fields(sampler_current) ->
|
|||
|
||||
monitor(get, #{query_string := QS, bindings := Bindings}) ->
|
||||
Latest = maps:get(<<"latest">>, QS, infinity),
|
||||
Node = binary_to_atom(maps:get(node, Bindings, <<"all">>)),
|
||||
RawNode = maps:get(node, Bindings, all),
|
||||
case emqx_misc:safe_to_existing_atom(RawNode, utf8) of
|
||||
{ok, Node} ->
|
||||
case emqx_dashboard_monitor:samplers(Node, Latest) of
|
||||
{badrpc, {Node, Reason}} ->
|
||||
Message = list_to_binary(io_lib:format("Bad node ~p, rpc failed ~p", [Node, Reason])),
|
||||
Message = list_to_binary(
|
||||
io_lib:format("Bad node ~p, rpc failed ~p", [Node, Reason])
|
||||
),
|
||||
{400, 'BAD_RPC', Message};
|
||||
Samplers ->
|
||||
{200, Samplers}
|
||||
end;
|
||||
_ ->
|
||||
Message = list_to_binary(io_lib:format("Bad node ~p", [RawNode])),
|
||||
{400, 'BAD_RPC', Message}
|
||||
end.
|
||||
|
||||
monitor_current(get, #{bindings := Bindings}) ->
|
||||
|
|
Loading…
Reference in New Issue