fix: apply suggestions from code review, thanks @zmstone
This commit is contained in:
parent
5dc96a37e2
commit
a40c7d646a
|
@ -512,7 +512,7 @@ plugin_config(put, #{bindings := #{name := NameVsn}, body := AvroJsonMap}) ->
|
|||
{ok, _} ->
|
||||
case emqx_plugins:decode_plugin_config_map(NameVsn, AvroJsonMap) of
|
||||
{ok, ?plugin_without_config_schema} ->
|
||||
%% no plugin avro schema, just put the json map it as-is
|
||||
%% no plugin avro schema, just put the json map as-is
|
||||
_Res = emqx_mgmt_api_plugins_proto_v3:update_plugin_config(
|
||||
Nodes, NameVsn, AvroJsonMap, ?plugin_without_config_schema
|
||||
),
|
||||
|
@ -616,7 +616,7 @@ ensure_action(Name, restart) ->
|
|||
) ->
|
||||
ok.
|
||||
do_update_plugin_config(NameVsn, AvroJsonMap, AvroValue) ->
|
||||
%% TODO: maybe use `PluginConfigMap` to validate config
|
||||
%% TODO: maybe use `AvroValue` to validate config
|
||||
emqx_plugins:put_config(NameVsn, AvroJsonMap, AvroValue).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
|
@ -162,7 +162,8 @@ ensure_installed(NameVsn) ->
|
|||
case ensure_exists_and_installed(NameVsn) of
|
||||
ok ->
|
||||
maybe_post_op_after_installed(NameVsn),
|
||||
_ = maybe_ensure_plugin_config(NameVsn);
|
||||
_ = maybe_ensure_plugin_config(NameVsn),
|
||||
ok;
|
||||
{error, _Reason} = Err ->
|
||||
Err
|
||||
end
|
||||
|
@ -1166,6 +1167,7 @@ do_create_config_dir(NameVsn) ->
|
|||
end
|
||||
end.
|
||||
|
||||
-spec maybe_ensure_plugin_config(name_vsn()) -> ok.
|
||||
maybe_ensure_plugin_config(NameVsn) ->
|
||||
maybe
|
||||
true ?= with_plugin_avsc(NameVsn),
|
||||
|
@ -1174,10 +1176,13 @@ maybe_ensure_plugin_config(NameVsn) ->
|
|||
_ -> ok
|
||||
end.
|
||||
|
||||
-spec ensure_plugin_config(name_vsn()) -> ok.
|
||||
ensure_plugin_config(NameVsn) ->
|
||||
%% fetch plugin hocon config from cluster
|
||||
Nodes = [N || N <- mria:running_nodes(), N /= node()],
|
||||
ensure_plugin_config(NameVsn, Nodes).
|
||||
|
||||
-spec ensure_plugin_config(name_vsn(), list()) -> ok.
|
||||
ensure_plugin_config(NameVsn, []) ->
|
||||
?SLOG(debug, #{
|
||||
msg => "default_plugin_config_used",
|
||||
|
@ -1200,6 +1205,7 @@ ensure_plugin_config(NameVsn, Nodes) ->
|
|||
cp_default_config_file(NameVsn)
|
||||
end.
|
||||
|
||||
-spec cp_default_config_file(name_vsn()) -> ok.
|
||||
cp_default_config_file(NameVsn) ->
|
||||
%% always copy default hocon file into config dir when can not get config from other nodes
|
||||
Source = default_plugin_config_file(NameVsn),
|
||||
|
@ -1211,7 +1217,6 @@ cp_default_config_file(NameVsn) ->
|
|||
ok = filelib:ensure_dir(Destination),
|
||||
case file:copy(Source, Destination) of
|
||||
{ok, _} ->
|
||||
ok,
|
||||
ensure_config_map(NameVsn);
|
||||
{error, Reason} ->
|
||||
?SLOG(warning, #{
|
||||
|
|
Loading…
Reference in New Issue