fix: plugin's internal config api
This commit is contained in:
parent
11389bc086
commit
00cab33fde
|
@ -488,7 +488,7 @@ update_plugin(put, #{bindings := #{name := Name, action := Action}}) ->
|
|||
plugin_config(get, #{bindings := #{name := NameVsn}}) ->
|
||||
case emqx_plugins:describe(NameVsn) of
|
||||
{ok, _} ->
|
||||
case emqx_plugins:get_plugin_config(NameVsn, #{format => ?CONFIG_FORMAT_MAP}) of
|
||||
case emqx_plugins:get_plugin_config(NameVsn) of
|
||||
{ok, AvroJson} ->
|
||||
{200, #{<<"content-type">> => <<"'application/json'">>}, AvroJson};
|
||||
{error, _} ->
|
||||
|
@ -503,8 +503,7 @@ plugin_config(get, #{bindings := #{name := NameVsn}}) ->
|
|||
plugin_config(put, #{bindings := #{name := NameVsn}, body := AvroJsonMap}) ->
|
||||
case emqx_plugins:describe(NameVsn) of
|
||||
{ok, _} ->
|
||||
AvroJsonBin = emqx_utils_json:encode(AvroJsonMap),
|
||||
case emqx_plugins:decode_plugin_avro_config(NameVsn, AvroJsonBin) of
|
||||
case emqx_plugins:decode_plugin_avro_config(NameVsn, AvroJsonMap) of
|
||||
{ok, AvroValueConfig} ->
|
||||
Nodes = emqx:running_nodes(),
|
||||
%% cluster call with config in map (binary key-value)
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
plugin_avsc/1,
|
||||
plugin_i18n/1,
|
||||
plugin_avro/1,
|
||||
parse_name_vsn/1
|
||||
parse_name_vsn/1,
|
||||
make_name_vsn_string/2
|
||||
]).
|
||||
|
||||
%% Package operations
|
||||
|
@ -49,19 +50,22 @@
|
|||
ensure_started/1,
|
||||
ensure_stopped/0,
|
||||
ensure_stopped/1,
|
||||
get_plugin_config/1,
|
||||
get_plugin_config/2,
|
||||
put_plugin_config/3,
|
||||
restart/1,
|
||||
list/0
|
||||
]).
|
||||
|
||||
%% Plugin config APIs
|
||||
-export([
|
||||
get_plugin_config/1,
|
||||
get_plugin_config/2,
|
||||
get_plugin_config/3,
|
||||
get_plugin_config/4,
|
||||
put_plugin_config/3
|
||||
]).
|
||||
|
||||
%% Package utils
|
||||
-export([
|
||||
decode_plugin_avro_config/2,
|
||||
get_config/2,
|
||||
put_config/2,
|
||||
get_tar/1,
|
||||
install_dir/0,
|
||||
avsc_file_path/1
|
||||
]).
|
||||
|
@ -73,6 +77,8 @@
|
|||
|
||||
%% Internal export
|
||||
-export([do_ensure_started/1]).
|
||||
%% for test cases
|
||||
-export([put_config/2]).
|
||||
|
||||
-ifdef(TEST).
|
||||
-compile(export_all).
|
||||
|
@ -124,6 +130,9 @@ parse_name_vsn(NameVsn) when is_list(NameVsn) ->
|
|||
_ -> {error, "bad_name_vsn"}
|
||||
end.
|
||||
|
||||
make_name_vsn_string(Name, Vsn) ->
|
||||
binary_to_list(iolist_to_binary([Name, "-", Vsn])).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Package operations
|
||||
|
||||
|
@ -246,21 +255,30 @@ ensure_stopped(NameVsn) ->
|
|||
end
|
||||
).
|
||||
|
||||
get_plugin_config(Name, Vsn, Options, Default) ->
|
||||
get_plugin_config(make_name_vsn_string(Name, Vsn), Options, Default).
|
||||
|
||||
-spec get_plugin_config(name_vsn()) ->
|
||||
{ok, plugin_config()} | {error, term()}.
|
||||
{ok, plugin_config()}
|
||||
| {error, term()}.
|
||||
get_plugin_config(NameVsn) ->
|
||||
get_plugin_config(bin(NameVsn), #{format => ?CONFIG_FORMAT_MAP}).
|
||||
|
||||
-spec get_plugin_config(name_vsn(), Options :: map()) ->
|
||||
{ok, avro_binary() | plugin_config()}
|
||||
| {error, term()}.
|
||||
|
||||
get_plugin_config(NameVsn, #{format := ?CONFIG_FORMAT_AVRO}) ->
|
||||
%% no default value when get raw binary config
|
||||
case read_plugin_avro(NameVsn) of
|
||||
{ok, _AvroJson} = Res -> Res;
|
||||
{error, _Reason} = Err -> Err
|
||||
end;
|
||||
get_plugin_config(NameVsn, #{format := ?CONFIG_FORMAT_MAP}) ->
|
||||
{ok, persistent_term:get(?PLUGIN_PERSIS_CONFIG_KEY(NameVsn), #{})}.
|
||||
get_plugin_config(NameVsn, Options = #{format := ?CONFIG_FORMAT_MAP}) ->
|
||||
get_plugin_config(NameVsn, Options, #{}).
|
||||
|
||||
get_plugin_config(NameVsn, #{format := ?CONFIG_FORMAT_MAP}, Default) ->
|
||||
{ok, persistent_term:get(?PLUGIN_PERSIS_CONFIG_KEY(NameVsn), Default)}.
|
||||
|
||||
%% @doc Update plugin's config.
|
||||
%% RPC call from Management API or CLI.
|
||||
|
|
Loading…
Reference in New Issue