Просмотр исходного кода

fix: apply suggestions from code review, thanks @zmstone

JimMoen 1 год назад
Родитель
Сommit
a40c7d646a

+ 2 - 2
apps/emqx_management/src/emqx_mgmt_api_plugins.erl

@@ -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).
 
 %%--------------------------------------------------------------------

+ 7 - 2
apps/emqx_plugins/src/emqx_plugins.erl

@@ -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, #{