fix: Handle obfuscated fields in bridges_probe API

This commit is contained in:
Serge Tupchii 2023-03-01 21:43:38 +02:00
parent b04f7ecccf
commit 77dea0c77a
1 changed files with 14 additions and 1 deletions

View File

@ -546,7 +546,8 @@ schema("/bridges_probe") ->
RequestMeta = #{module => ?MODULE, method => post, path => "/bridges_probe"},
case emqx_dashboard_swagger:filter_check_request_and_translate_body(Request, RequestMeta) of
{ok, #{body := #{<<"type">> := ConnType} = Params}} ->
case emqx_bridge_resource:create_dry_run(ConnType, maps:remove(<<"type">>, Params)) of
Params1 = maybe_deobfuscate_bridge_probe(Params),
case emqx_bridge_resource:create_dry_run(ConnType, maps:remove(<<"type">>, Params1)) of
ok ->
{204};
{error, Error} ->
@ -556,6 +557,18 @@ schema("/bridges_probe") ->
BadRequest
end.
maybe_deobfuscate_bridge_probe(#{<<"type">> := BridgeType, <<"name">> := BridgeName} = Params) ->
case emqx_bridge:lookup(BridgeType, BridgeName) of
{ok, _} ->
RawConf = emqx:get_raw_config([bridges, BridgeType, BridgeName], #{}),
deobfuscate(Params, RawConf);
_ ->
%% A bridge may be probed before it's created, so not finding it here is fine
Params
end;
maybe_deobfuscate_bridge_probe(Params) ->
Params.
lookup_from_all_nodes(BridgeType, BridgeName, SuccCode) ->
FormatFun = fun format_bridge_info_without_metrics/1,
do_lookup_from_all_nodes(BridgeType, BridgeName, SuccCode, FormatFun).