feat(emqx_resource): update the unused APIs

This commit is contained in:
Shawn 2021-06-07 17:20:34 +08:00
parent 2ff92d2880
commit 4914b003ac
3 changed files with 4 additions and 18 deletions

View File

@ -19,7 +19,6 @@
-include_lib("emqx_resource/include/emqx_resource_behaviour.hrl"). -include_lib("emqx_resource/include/emqx_resource_behaviour.hrl").
-export([ on_jsonify/1 -export([ on_jsonify/1
, on_api_reply_format/1
]). ]).
%% callbacks of behaviour emqx_resource %% callbacks of behaviour emqx_resource
@ -51,11 +50,6 @@ on_jsonify(#{<<"server">> := Server, <<"user">> := User, <<"database">> := DB,
<<"certfile">> => list_to_binary(CertFile) <<"certfile">> => list_to_binary(CertFile)
}. }.
on_api_reply_format(ResourceData) ->
#{config := Conf} = Reply0 = emqx_resource_api:default_api_reply_format(ResourceData),
Reply0#{config => maps:without([<<"cacertfile">>, <<"keyfile">>,
<<"certfile">>, <<"verify">>], Conf)}.
%% =================================================================== %% ===================================================================
on_start(InstId, #{<<"server">> := {Host, Port}, on_start(InstId, #{<<"server">> := {Host, Port},

View File

@ -64,7 +64,7 @@ create_bridge(#{name := Name}, Params) ->
{error, already_created} -> {error, already_created} ->
{400, #{code => 102, message => <<"bridge already created: ", Name/binary>>}}; {400, #{code => 102, message => <<"bridge already created: ", Name/binary>>}};
{error, Reason0} -> {error, Reason0} ->
Reason = emqx_data_bridge_api:stringnify(Reason0), Reason = emqx_resource_api:stringnify(Reason0),
{500, #{code => 102, message => <<"create bridge ", Name/binary, {500, #{code => 102, message => <<"create bridge ", Name/binary,
" failed:", Reason/binary>>}} " failed:", Reason/binary>>}}
end. end.
@ -72,7 +72,7 @@ create_bridge(#{name := Name}, Params) ->
update_bridge(#{name := Name}, Params) -> update_bridge(#{name := Name}, Params) ->
Config = proplists:get_value(<<"config">>, Params), Config = proplists:get_value(<<"config">>, Params),
BridgeType = proplists:get_value(<<"type">>, Params), BridgeType = proplists:get_value(<<"type">>, Params),
case emqx_resource:check_and_udpate( case emqx_resource:check_and_update(
emqx_data_bridge:resource_id(Name), emqx_data_bridge:resource_id(Name),
emqx_data_bridge:resource_type(BridgeType), Config, []) of emqx_data_bridge:resource_type(BridgeType), Config, []) of
{ok, Data} -> {ok, Data} ->
@ -80,7 +80,7 @@ update_bridge(#{name := Name}, Params) ->
{error, not_found} -> {error, not_found} ->
{400, #{code => 102, message => <<"bridge not_found: ", Name/binary>>}}; {400, #{code => 102, message => <<"bridge not_found: ", Name/binary>>}};
{error, Reason0} -> {error, Reason0} ->
Reason = emqx_data_bridge_api:stringnify(Reason0), Reason = emqx_resource_api:stringnify(Reason0),
{500, #{code => 102, message => <<"update bridge ", Name/binary, {500, #{code => 102, message => <<"update bridge ", Name/binary,
" failed:", Reason/binary>>}} " failed:", Reason/binary>>}}
end. end.
@ -89,7 +89,7 @@ delete_bridge(#{name := Name}, _Params) ->
case emqx_resource:remove(emqx_data_bridge:resource_id(Name)) of case emqx_resource:remove(emqx_data_bridge:resource_id(Name)) of
ok -> {200, #{code => 0, data => #{}}}; ok -> {200, #{code => 0, data => #{}}};
{error, Reason} -> {error, Reason} ->
{500, #{code => 102, message => emqx_data_bridge_api:stringnify(Reason)}} {500, #{code => 102, message => emqx_resource_api:stringnify(Reason)}}
end. end.
is_bridge(#{id := <<"bridge:", _/binary>>}) -> is_bridge(#{id := <<"bridge:", _/binary>>}) ->

View File

@ -73,7 +73,6 @@
, call_stop/3 %% stop the instance , call_stop/3 %% stop the instance
, call_config_merge/4 %% merge the config when updating , call_config_merge/4 %% merge the config when updating
, call_jsonify/2 , call_jsonify/2
, call_api_reply_format/2
]). ]).
-export([ list_instances/0 %% list all the instances, id only. -export([ list_instances/0 %% list all the instances, id only.
@ -272,13 +271,6 @@ call_jsonify(Mod, Config) ->
true -> ?SAFE_CALL(Mod:on_jsonify(Config)) true -> ?SAFE_CALL(Mod:on_jsonify(Config))
end. end.
-spec call_api_reply_format(module(), resource_data()) -> jsx:json_term().
call_api_reply_format(Mod, Data) ->
case erlang:function_exported(Mod, on_api_reply_format, 1) of
false -> emqx_resource_api:default_api_reply_format(Data);
true -> ?SAFE_CALL(Mod:on_api_reply_format(Data))
end.
-spec check_config(resource_type(), binary() | term()) -> -spec check_config(resource_type(), binary() | term()) ->
{ok, resource_config()} | {error, term()}. {ok, resource_config()} | {error, term()}.
check_config(ResourceType, RawConfig) when is_binary(RawConfig) -> check_config(ResourceType, RawConfig) when is_binary(RawConfig) ->