From 862336a2cbf1f37bdadfcbff31744c241011532d Mon Sep 17 00:00:00 2001 From: Shawn <506895667@qq.com> Date: Mon, 22 Jul 2024 15:45:08 +0800 Subject: [PATCH] feat: hide relup plugins from APIs and CLIs --- .../src/emqx_mgmt_api_relup.erl | 4 ++-- apps/emqx_plugins/src/emqx_plugins.erl | 24 ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/apps/emqx_management/src/emqx_mgmt_api_relup.erl b/apps/emqx_management/src/emqx_mgmt_api_relup.erl index e7ee7c317..05078c1ac 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_relup.erl +++ b/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) -> diff --git a/apps/emqx_plugins/src/emqx_plugins.erl b/apps/emqx_plugins/src/emqx_plugins.erl index c7ae9fd2c..37df54d3f 100644 --- a/apps/emqx_plugins/src/emqx_plugins.erl +++ b/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)]