Merge pull request #12124 from thalesmg/fix-connector-fill-defaults-r54-20231207

fix(connectors_api): fill default raw config values before returning
This commit is contained in:
Thales Macedo Garitezi 2023-12-07 11:01:42 -03:00 committed by GitHub
commit cf3dd85684
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -610,11 +610,12 @@ format_resource(
#{
type := Type,
name := ConnectorName,
raw_config := RawConf,
raw_config := RawConf0,
resource_data := ResourceData
},
Node
) ->
RawConf = fill_defaults(Type, RawConf0),
redact(
maps:merge(
RawConf#{
@ -638,6 +639,20 @@ format_resource_data(added_channels, Channels, Result) ->
format_resource_data(K, V, Result) ->
Result#{K => V}.
fill_defaults(Type, RawConf) ->
PackedConf = pack_connector_conf(Type, RawConf),
FullConf = emqx_config:fill_defaults(emqx_connector_schema, PackedConf, #{}),
unpack_connector_conf(Type, FullConf).
pack_connector_conf(Type, RawConf) ->
#{<<"connectors">> => #{bin(Type) => #{<<"foo">> => RawConf}}}.
unpack_connector_conf(Type, PackedConf) ->
TypeBin = bin(Type),
#{<<"connectors">> := Bridges} = PackedConf,
#{<<"foo">> := RawConf} = maps:get(TypeBin, Bridges),
RawConf.
format_action(ActionId) ->
element(2, emqx_bridge_v2:parse_id(ActionId)).

View File

@ -845,6 +845,19 @@ t_fail_delete_with_action(Config) ->
),
ok.
t_raw_config_response_defaults(Config) ->
Params = maps:without([<<"enable">>, <<"resource_opts">>], ?KAFKA_CONNECTOR(?CONNECTOR_NAME)),
?assertMatch(
{ok, 201, #{<<"enable">> := true, <<"resource_opts">> := #{}}},
request_json(
post,
uri(["connectors"]),
Params,
Config
)
),
ok.
%%% helpers
listen_on_random_port() ->
SockOpts = [binary, {active, false}, {packet, raw}, {reuseaddr, true}, {backlog, 1000}],