浏览代码

feat: hide relup plugins from APIs and CLIs

Shawn 1 年之前
父节点
当前提交
862336a2cb
共有 2 个文件被更改,包括 20 次插入8 次删除
  1. 2 2
      apps/emqx_management/src/emqx_mgmt_api_relup.erl
  2. 18 6
      apps/emqx_plugins/src/emqx_plugins.erl

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

@@ -104,7 +104,7 @@ schema("/relup/package/upload") ->
             responses => #{
                 204 => <<"Package is uploaded successfully">>,
                 400 => emqx_dashboard_swagger:error_codes(
-                    ['UNEXPECTED_ERROR', 'BAD_PLUGIN_INFO']
+                    ['UNEXPECTED_ERROR', 'ALREADY_INSTALLED', 'BAD_PLUGIN_INFO']
                 )
             }
         }
@@ -590,7 +590,7 @@ get_installed_packages() ->
                 _ -> false
             end
         end,
-        emqx_plugins:list()
+        emqx_plugins:list(hidden)
     ).
 
 target_vsn_from_rel_vsn(Vsn) ->

+ 18 - 6
apps/emqx_plugins/src/emqx_plugins.erl

@@ -56,7 +56,8 @@
     ensure_stopped/0,
     ensure_stopped/1,
     restart/1,
-    list/0
+    list/0,
+    list/1
 ]).
 
 %% Plugin config APIs
@@ -378,13 +379,17 @@ restart(NameVsn) ->
 %% Including the ones that are installed, but not enabled in config.
 -spec list() -> [plugin_info()].
 list() ->
+    list(normal).
+
+-spec list(all | normal | hidden) -> [plugin_info()].
+list(Type) ->
     Pattern = filename:join([install_dir(), "*", "release.json"]),
     All = lists:filtermap(
         fun(JsonFilePath) ->
             [_, NameVsn | _] = lists:reverse(filename:split(JsonFilePath)),
             case read_plugin_info(NameVsn, #{}) of
                 {ok, Info} ->
-                    {true, Info};
+                    filter_plugin_of_type(Type, Info);
                 {error, Reason} ->
                     ?SLOG(warning, Reason#{msg => "failed_to_read_plugin_info"}),
                     false
@@ -394,6 +399,17 @@ list() ->
     ),
     do_list(configured(), All).
 
+filter_plugin_of_type(all, Info) ->
+    {true, Info};
+filter_plugin_of_type(normal, #{<<"hidden">> := true}) ->
+    false;
+filter_plugin_of_type(normal, Info) ->
+    {true, Info};
+filter_plugin_of_type(hidden, #{<<"hidden">> := true} = Info) ->
+    {true, Info};
+filter_plugin_of_type(hidden, _Info) ->
+    false.
+
 %%--------------------------------------------------------------------
 %% Package utils
 
@@ -662,10 +678,6 @@ do_list([#{name_vsn := NameVsn} | Rest], All) ->
     end,
     case lists:splitwith(SplitF, All) of
         {_, []} ->
-            ?SLOG(warning, #{
-                msg => "configured_plugin_not_installed",
-                name_vsn => NameVsn
-            }),
             do_list(Rest, All);
         {Front, [I | Rear]} ->
             [I | do_list(Rest, Front ++ Rear)]