feat(emqx_resource): update the unused APIs
This commit is contained in:
parent
2ff92d2880
commit
4914b003ac
|
@ -19,7 +19,6 @@
|
|||
-include_lib("emqx_resource/include/emqx_resource_behaviour.hrl").
|
||||
|
||||
-export([ on_jsonify/1
|
||||
, on_api_reply_format/1
|
||||
]).
|
||||
|
||||
%% callbacks of behaviour emqx_resource
|
||||
|
@ -51,11 +50,6 @@ on_jsonify(#{<<"server">> := Server, <<"user">> := User, <<"database">> := DB,
|
|||
<<"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},
|
||||
|
|
|
@ -64,7 +64,7 @@ create_bridge(#{name := Name}, Params) ->
|
|||
{error, already_created} ->
|
||||
{400, #{code => 102, message => <<"bridge already created: ", Name/binary>>}};
|
||||
{error, Reason0} ->
|
||||
Reason = emqx_data_bridge_api:stringnify(Reason0),
|
||||
Reason = emqx_resource_api:stringnify(Reason0),
|
||||
{500, #{code => 102, message => <<"create bridge ", Name/binary,
|
||||
" failed:", Reason/binary>>}}
|
||||
end.
|
||||
|
@ -72,7 +72,7 @@ create_bridge(#{name := Name}, Params) ->
|
|||
update_bridge(#{name := Name}, Params) ->
|
||||
Config = proplists:get_value(<<"config">>, 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_type(BridgeType), Config, []) of
|
||||
{ok, Data} ->
|
||||
|
@ -80,7 +80,7 @@ update_bridge(#{name := Name}, Params) ->
|
|||
{error, not_found} ->
|
||||
{400, #{code => 102, message => <<"bridge not_found: ", Name/binary>>}};
|
||||
{error, Reason0} ->
|
||||
Reason = emqx_data_bridge_api:stringnify(Reason0),
|
||||
Reason = emqx_resource_api:stringnify(Reason0),
|
||||
{500, #{code => 102, message => <<"update bridge ", Name/binary,
|
||||
" failed:", Reason/binary>>}}
|
||||
end.
|
||||
|
@ -89,7 +89,7 @@ delete_bridge(#{name := Name}, _Params) ->
|
|||
case emqx_resource:remove(emqx_data_bridge:resource_id(Name)) of
|
||||
ok -> {200, #{code => 0, data => #{}}};
|
||||
{error, Reason} ->
|
||||
{500, #{code => 102, message => emqx_data_bridge_api:stringnify(Reason)}}
|
||||
{500, #{code => 102, message => emqx_resource_api:stringnify(Reason)}}
|
||||
end.
|
||||
|
||||
is_bridge(#{id := <<"bridge:", _/binary>>}) ->
|
||||
|
|
|
@ -73,7 +73,6 @@
|
|||
, call_stop/3 %% stop the instance
|
||||
, call_config_merge/4 %% merge the config when updating
|
||||
, call_jsonify/2
|
||||
, call_api_reply_format/2
|
||||
]).
|
||||
|
||||
-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))
|
||||
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()) ->
|
||||
{ok, resource_config()} | {error, term()}.
|
||||
check_config(ResourceType, RawConfig) when is_binary(RawConfig) ->
|
||||
|
|
Loading…
Reference in New Issue