feat(connector_api): list disabled channels too
Fixes https://emqx.atlassian.net/browse/EMQX-11583
This commit is contained in:
parent
d7b96af893
commit
6e49cce055
|
@ -611,10 +611,11 @@ format_resource(
|
||||||
type := Type,
|
type := Type,
|
||||||
name := ConnectorName,
|
name := ConnectorName,
|
||||||
raw_config := RawConf0,
|
raw_config := RawConf0,
|
||||||
resource_data := ResourceData
|
resource_data := ResourceData0
|
||||||
},
|
},
|
||||||
Node
|
Node
|
||||||
) ->
|
) ->
|
||||||
|
ResourceData = lookup_channels(Type, ConnectorName, ResourceData0),
|
||||||
RawConf = fill_defaults(Type, RawConf0),
|
RawConf = fill_defaults(Type, RawConf0),
|
||||||
redact(
|
redact(
|
||||||
maps:merge(
|
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) ->
|
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) ->
|
format_resource_data(error, undefined, Result) ->
|
||||||
Result;
|
Result;
|
||||||
format_resource_data(error, Error, Result) ->
|
format_resource_data(error, Error, Result) ->
|
||||||
Result#{status_reason => emqx_utils:readable_error_msg(Error)};
|
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))};
|
Result#{actions => lists:map(fun format_action/1, maps:keys(Channels))};
|
||||||
format_resource_data(K, V, Result) ->
|
format_resource_data(K, V, Result) ->
|
||||||
Result#{K => V}.
|
Result#{K => V}.
|
||||||
|
|
|
@ -845,6 +845,39 @@ t_fail_delete_with_action(Config) ->
|
||||||
),
|
),
|
||||||
ok.
|
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) ->
|
t_raw_config_response_defaults(Config) ->
|
||||||
Params = maps:without([<<"enable">>, <<"resource_opts">>], ?KAFKA_CONNECTOR(?CONNECTOR_NAME)),
|
Params = maps:without([<<"enable">>, <<"resource_opts">>], ?KAFKA_CONNECTOR(?CONNECTOR_NAME)),
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
|
|
Loading…
Reference in New Issue