feat(connector_api): list disabled channels too

Fixes https://emqx.atlassian.net/browse/EMQX-11583
This commit is contained in:
Thales Macedo Garitezi 2023-12-12 11:20:33 -03:00
parent d7b96af893
commit 6e49cce055
2 changed files with 46 additions and 3 deletions

View File

@ -611,10 +611,11 @@ format_resource(
type := Type,
name := ConnectorName,
raw_config := RawConf0,
resource_data := ResourceData
resource_data := ResourceData0
},
Node
) ->
ResourceData = lookup_channels(Type, ConnectorName, ResourceData0),
RawConf = fill_defaults(Type, RawConf0),
redact(
maps:merge(
@ -627,14 +628,23 @@ format_resource(
)
).
lookup_channels(Type, Name, ResourceData0) ->
ConnectorResId = emqx_connector_resource:resource_id(Type, Name),
case emqx_resource:get_channels(ConnectorResId) of
{ok, Channels} ->
ResourceData0#{channels => maps:from_list(Channels)};
{error, not_found} ->
ResourceData0#{channels => #{}}
end.
format_resource_data(ResData) ->
maps:fold(fun format_resource_data/3, #{}, maps:with([status, error, added_channels], ResData)).
maps:fold(fun format_resource_data/3, #{}, maps:with([status, error, channels], ResData)).
format_resource_data(error, undefined, Result) ->
Result;
format_resource_data(error, Error, Result) ->
Result#{status_reason => emqx_utils:readable_error_msg(Error)};
format_resource_data(added_channels, Channels, Result) ->
format_resource_data(channels, Channels, Result) ->
Result#{actions => lists:map(fun format_action/1, maps:keys(Channels))};
format_resource_data(K, V, Result) ->
Result#{K => V}.

View File

@ -845,6 +845,39 @@ t_fail_delete_with_action(Config) ->
),
ok.
t_list_disabled_channels(Config) ->
ConnectorParams = ?KAFKA_CONNECTOR(?CONNECTOR_NAME),
?assertMatch(
{ok, 201, _},
request_json(
post,
uri(["connectors"]),
ConnectorParams,
Config
)
),
ActionName = ?BRIDGE_NAME,
ActionParams = (?KAFKA_BRIDGE(ActionName))#{<<"enable">> := true},
?assertMatch(
{ok, 201, #{<<"enable">> := true}},
request_json(
post,
uri(["actions"]),
ActionParams,
Config
)
),
ConnectorID = emqx_connector_resource:connector_id(?CONNECTOR_TYPE, ?CONNECTOR_NAME),
?assertMatch(
{ok, 200, #{<<"actions">> := [ActionName]}},
request_json(
get,
uri(["connectors", ConnectorID]),
Config
)
),
ok.
t_raw_config_response_defaults(Config) ->
Params = maps:without([<<"enable">>, <<"resource_opts">>], ?KAFKA_CONNECTOR(?CONNECTOR_NAME)),
?assertMatch(