fix(connector): add type and name in repsonse of GET /connectors

This commit is contained in:
Shawn 2021-12-17 16:45:42 +08:00
parent 8be2aaf72c
commit 9b34f6f9a3
2 changed files with 8 additions and 2 deletions

View File

@ -209,7 +209,7 @@ schema("/connectors/:id") ->
end.
'/connectors'(get, _Request) ->
{200, emqx_connector:list()};
{200, [format_resp(Conn) || Conn <- emqx_connector:list()]};
'/connectors'(post, #{body := #{<<"type">> := ConnType} = Params}) ->
ConnName = maps:get(<<"name">>, Params, emqx_misc:gen_id()),
@ -264,10 +264,16 @@ error_msg(Code, Msg) when is_binary(Msg) ->
error_msg(Code, Msg) ->
#{code => Code, message => bin(io_lib:format("~p", [Msg]))}.
format_resp(#{<<"id">> := Id} = RawConf) ->
format_resp(Id, RawConf).
format_resp(ConnId, RawConf) ->
NumOfBridges = length(emqx_bridge:list_bridges_by_connector(ConnId)),
{Type, Name} = emqx_connector:parse_connector_id(ConnId),
RawConf#{
<<"id">> => ConnId,
<<"type">> => Type,
<<"name">> => Name,
<<"num_of_bridges">> => NumOfBridges
}.

View File

@ -8,7 +8,7 @@
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% cluster_shareload under the License is cluster_shareload on an "AS IS" BASIS,
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.