|
@@ -220,8 +220,8 @@ schema("/connectors/:id") ->
|
|
|
case emqx_connector:update(ConnType, ConnName,
|
|
case emqx_connector:update(ConnType, ConnName,
|
|
|
maps:without([<<"type">>, <<"name">>], Params)) of
|
|
maps:without([<<"type">>, <<"name">>], Params)) of
|
|
|
{ok, #{raw_config := RawConf}} ->
|
|
{ok, #{raw_config := RawConf}} ->
|
|
|
- {201, RawConf#{<<"id">> =>
|
|
|
|
|
- emqx_connector:connector_id(ConnType, ConnName)}};
|
|
|
|
|
|
|
+ Id = emqx_connector:connector_id(ConnType, ConnName),
|
|
|
|
|
+ {201, format_resp(Id, RawConf)};
|
|
|
{error, Error} -> {400, error_msg('BAD_ARG', Error)}
|
|
{error, Error} -> {400, error_msg('BAD_ARG', Error)}
|
|
|
end
|
|
end
|
|
|
end.
|
|
end.
|
|
@@ -229,7 +229,7 @@ schema("/connectors/:id") ->
|
|
|
'/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(ConnType, ConnName) of
|
|
|
- {ok, Conf} -> {200, Conf#{<<"id">> => Id}};
|
|
|
|
|
|
|
+ {ok, Conf} -> {200, format_resp(Id, Conf)};
|
|
|
{error, not_found} ->
|
|
{error, not_found} ->
|
|
|
{404, error_msg('NOT_FOUND', <<"connector not found">>)}
|
|
{404, error_msg('NOT_FOUND', <<"connector not found">>)}
|
|
|
end);
|
|
end);
|
|
@@ -239,7 +239,8 @@ schema("/connectors/:id") ->
|
|
|
case emqx_connector:lookup(ConnType, ConnName) of
|
|
case emqx_connector:lookup(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}} -> {200, RawConf#{<<"id">> => Id}};
|
|
|
|
|
|
|
+ {ok, #{raw_config := RawConf}} ->
|
|
|
|
|
+ {200, format_resp(Id, RawConf)};
|
|
|
{error, Error} -> {400, error_msg('BAD_ARG', Error)}
|
|
{error, Error} -> {400, error_msg('BAD_ARG', Error)}
|
|
|
end;
|
|
end;
|
|
|
{error, not_found} ->
|
|
{error, not_found} ->
|
|
@@ -263,5 +264,12 @@ error_msg(Code, Msg) when is_binary(Msg) ->
|
|
|
error_msg(Code, Msg) ->
|
|
error_msg(Code, Msg) ->
|
|
|
#{code => Code, message => bin(io_lib:format("~p", [Msg]))}.
|
|
#{code => Code, message => bin(io_lib:format("~p", [Msg]))}.
|
|
|
|
|
|
|
|
|
|
+format_resp(ConnId, RawConf) ->
|
|
|
|
|
+ NumOfBridges = length(emqx_bridge:list_bridges_by_connector(ConnId)),
|
|
|
|
|
+ RawConf#{
|
|
|
|
|
+ <<"id">> => ConnId,
|
|
|
|
|
+ <<"num_of_bridges">> => NumOfBridges
|
|
|
|
|
+ }.
|
|
|
|
|
+
|
|
|
bin(S) when is_list(S) ->
|
|
bin(S) when is_list(S) ->
|
|
|
list_to_binary(S).
|
|
list_to_binary(S).
|