fix(actions_api): fill raw config defaults before returning

Fixes https://emqx.atlassian.net/browse/EMQX-11541
This commit is contained in:
Thales Macedo Garitezi 2023-12-06 10:45:19 -03:00
parent 8a5b0d252d
commit 2757b95850
3 changed files with 32 additions and 4 deletions

View File

@ -799,11 +799,12 @@ format_resource(
name := Name, name := Name,
status := Status, status := Status,
error := Error, error := Error,
raw_config := RawConf, raw_config := RawConf0,
resource_data := _ResourceData resource_data := _ResourceData
}, },
Node Node
) -> ) ->
RawConf = fill_defaults(Type, RawConf0),
redact( redact(
maps:merge( maps:merge(
RawConf#{ RawConf#{
@ -934,6 +935,20 @@ aggregate_metrics(
M17 + N17 M17 + N17
). ).
fill_defaults(Type, RawConf) ->
PackedConf = pack_bridge_conf(Type, RawConf),
FullConf = emqx_config:fill_defaults(emqx_bridge_v2_schema, PackedConf, #{}),
unpack_bridge_conf(Type, FullConf).
pack_bridge_conf(Type, RawConf) ->
#{<<"actions">> => #{bin(Type) => #{<<"foo">> => RawConf}}}.
unpack_bridge_conf(Type, PackedConf) ->
TypeBin = bin(Type),
#{<<"actions">> := Bridges} = PackedConf,
#{<<"foo">> := RawConf} = maps:get(TypeBin, Bridges),
RawConf.
format_bridge_status_and_error(Data) -> format_bridge_status_and_error(Data) ->
maps:fold(fun format_resource_data/3, #{}, maps:with([status, error], Data)). maps:fold(fun format_resource_data/3, #{}, maps:with([status, error], Data)).

View File

@ -304,7 +304,7 @@ t_bridges_lifecycle(Config) ->
<<"status">> := <<"connected">>, <<"status">> := <<"connected">>,
<<"node_status">> := [_ | _], <<"node_status">> := [_ | _],
<<"connector">> := ?CONNECTOR_NAME, <<"connector">> := ?CONNECTOR_NAME,
<<"kafka">> := #{}, <<"parameters">> := #{},
<<"local_topic">> := _, <<"local_topic">> := _,
<<"resource_opts">> := _ <<"resource_opts">> := _
}}, }},
@ -1138,6 +1138,19 @@ t_cluster_later_join_metrics(Config) ->
), ),
ok. ok.
t_raw_config_response_defaults(Config) ->
Params = maps:remove(<<"enable">>, ?KAFKA_BRIDGE(?BRIDGE_NAME)),
?assertMatch(
{ok, 201, #{<<"enable">> := true}},
request_json(
post,
uri([?ROOT]),
Params,
Config
)
),
ok.
%%% helpers %%% helpers
listen_on_random_port() -> listen_on_random_port() ->
SockOpts = [binary, {active, false}, {packet, raw}, {reuseaddr, true}, {backlog, 1000}], SockOpts = [binary, {active, false}, {packet, raw}, {reuseaddr, true}, {backlog, 1000}],

View File

@ -766,7 +766,7 @@ t_actions_field(Config) ->
<<"status">> := <<"connected">>, <<"status">> := <<"connected">>,
<<"node_status">> := [_ | _], <<"node_status">> := [_ | _],
<<"connector">> := Name, <<"connector">> := Name,
<<"kafka">> := #{}, <<"parameters">> := #{},
<<"local_topic">> := _, <<"local_topic">> := _,
<<"resource_opts">> := _ <<"resource_opts">> := _
}}, }},
@ -821,7 +821,7 @@ t_fail_delete_with_action(Config) ->
<<"status">> := <<"connected">>, <<"status">> := <<"connected">>,
<<"node_status">> := [_ | _], <<"node_status">> := [_ | _],
<<"connector">> := Name, <<"connector">> := Name,
<<"kafka">> := #{}, <<"parameters">> := #{},
<<"local_topic">> := _, <<"local_topic">> := _,
<<"resource_opts">> := _ <<"resource_opts">> := _
}}, }},