refactor(connector): rename list/0 -> list_raw/0
This commit is contained in:
parent
50d0a3271b
commit
a38cac0233
|
@ -21,9 +21,9 @@
|
|||
, connector_id/2
|
||||
]).
|
||||
|
||||
-export([ list/0
|
||||
, lookup/1
|
||||
, lookup/2
|
||||
-export([ list_raw/0
|
||||
, lookup_raw/1
|
||||
, lookup_raw/2
|
||||
, create_dry_run/2
|
||||
, update/2
|
||||
, update/3
|
||||
|
@ -68,18 +68,18 @@ parse_connector_id(ConnectorId) ->
|
|||
_ -> error({invalid_connector_id, ConnectorId})
|
||||
end.
|
||||
|
||||
list() ->
|
||||
list_raw() ->
|
||||
lists:foldl(fun({Type, NameAndConf}, Connectors) ->
|
||||
lists:foldl(fun({Name, RawConf}, Acc) ->
|
||||
[RawConf#{<<"type">> => Type, <<"name">> => Name} | Acc]
|
||||
end, Connectors, maps:to_list(NameAndConf))
|
||||
end, [], maps:to_list(emqx:get_raw_config(config_key_path(), #{}))).
|
||||
|
||||
lookup(Id) when is_binary(Id) ->
|
||||
lookup_raw(Id) when is_binary(Id) ->
|
||||
{Type, Name} = parse_connector_id(Id),
|
||||
lookup(Type, Name).
|
||||
lookup_raw(Type, Name).
|
||||
|
||||
lookup(Type, Name) ->
|
||||
lookup_raw(Type, Name) ->
|
||||
case emqx:get_raw_config(config_key_path() ++ [Type, Name], not_found) of
|
||||
not_found -> {error, not_found};
|
||||
Conf -> {ok, Conf#{<<"type">> => Type, <<"name">> => Name}}
|
||||
|
|
|
@ -205,10 +205,10 @@ schema("/connectors/:id") ->
|
|||
end.
|
||||
|
||||
'/connectors'(get, _Request) ->
|
||||
{200, [format_resp(Conn) || Conn <- emqx_connector:list()]};
|
||||
{200, [format_resp(Conn) || Conn <- emqx_connector:list_raw()]};
|
||||
|
||||
'/connectors'(post, #{body := #{<<"type">> := ConnType, <<"name">> := ConnName} = Params}) ->
|
||||
case emqx_connector:lookup(ConnType, ConnName) of
|
||||
case emqx_connector:lookup_raw(ConnType, ConnName) of
|
||||
{ok, _} ->
|
||||
{400, error_msg('ALREADY_EXISTS', <<"connector already exists">>)};
|
||||
{error, not_found} ->
|
||||
|
@ -218,13 +218,13 @@ schema("/connectors/:id") ->
|
|||
{201, format_resp(RawConf#{<<"type">> => ConnType,
|
||||
<<"name">> => ConnName})};
|
||||
{error, Error} ->
|
||||
{400, error_msg('ALREADY_EXISTS', Error)}
|
||||
{400, error_msg('BAD_REQUEST', Error)}
|
||||
end
|
||||
end.
|
||||
|
||||
'/connectors/:id'(get, #{bindings := #{id := Id}}) ->
|
||||
?TRY_PARSE_ID(Id,
|
||||
case emqx_connector:lookup(ConnType, ConnName) of
|
||||
case emqx_connector:lookup_raw(ConnType, ConnName) of
|
||||
{ok, Conf} ->
|
||||
{200, format_resp(Conf)};
|
||||
{error, not_found} ->
|
||||
|
@ -234,7 +234,7 @@ schema("/connectors/:id") ->
|
|||
'/connectors/:id'(put, #{bindings := #{id := Id}, body := Params0}) ->
|
||||
Params = filter_out_request_body(Params0),
|
||||
?TRY_PARSE_ID(Id,
|
||||
case emqx_connector:lookup(ConnType, ConnName) of
|
||||
case emqx_connector:lookup_raw(ConnType, ConnName) of
|
||||
{ok, _} ->
|
||||
case emqx_connector:update(ConnType, ConnName, Params) of
|
||||
{ok, #{raw_config := RawConf}} ->
|
||||
|
@ -249,7 +249,7 @@ schema("/connectors/:id") ->
|
|||
|
||||
'/connectors/:id'(delete, #{bindings := #{id := Id}}) ->
|
||||
?TRY_PARSE_ID(Id,
|
||||
case emqx_connector:lookup(ConnType, ConnName) of
|
||||
case emqx_connector:lookup_raw(ConnType, ConnName) of
|
||||
{ok, _} ->
|
||||
case emqx_connector:delete(ConnType, ConnName) of
|
||||
{ok, _} ->
|
||||
|
|
|
@ -114,15 +114,6 @@ set_special_configs(_) ->
|
|||
|
||||
init_per_testcase(_, Config) ->
|
||||
{ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000),
|
||||
%% assert we there's no connectors and no bridges at first
|
||||
{ok, 200, Connectors} = request(get, uri(["connectors"]), []),
|
||||
lists:foreach(fun(#{<<"id">> := ConnectorID}) ->
|
||||
{ok, 200, <<>>} = request(delete, uri(["connectors", ConnectorID]), [])
|
||||
end, jsx:decode(Connectors)),
|
||||
{ok, 200, Bridges} = request(get, uri(["bridges"]), []),
|
||||
lists:foreach(fun(#{<<"id">> := BridgeID}) ->
|
||||
{ok, 204, <<>>} = request(delete, uri(["bridges", BridgeID]), [])
|
||||
end, jsx:decode(Bridges)),
|
||||
Config.
|
||||
end_per_testcase(_, _Config) ->
|
||||
clear_resources(),
|
||||
|
@ -135,9 +126,9 @@ clear_resources() ->
|
|||
lists:foreach(fun(#{type := Type, name := Name}) ->
|
||||
ok = emqx_bridge:remove(Type, Name)
|
||||
end, emqx_bridge:list()),
|
||||
lists:foreach(fun(#{type := Type, name := Name}) ->
|
||||
lists:foreach(fun(#{<<"type">> := Type, <<"name">> := Name}) ->
|
||||
ok = emqx_connector:delete(Type, Name)
|
||||
end, emqx_connector:list()).
|
||||
end, emqx_connector:list_raw()).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Testcases
|
||||
|
|
Loading…
Reference in New Issue