feat: hide relup plugins from APIs and CLIs

This commit is contained in:
Shawn 2024-07-22 15:45:08 +08:00
parent fc3405fe4c
commit 862336a2cb
2 changed files with 20 additions and 8 deletions

View File

@ -104,7 +104,7 @@ schema("/relup/package/upload") ->
responses => #{ responses => #{
204 => <<"Package is uploaded successfully">>, 204 => <<"Package is uploaded successfully">>,
400 => emqx_dashboard_swagger:error_codes( 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 _ -> false
end end
end, end,
emqx_plugins:list() emqx_plugins:list(hidden)
). ).
target_vsn_from_rel_vsn(Vsn) -> target_vsn_from_rel_vsn(Vsn) ->

View File

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