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