From 5434aa02ffcf51230c88a8711642e22e87778d02 Mon Sep 17 00:00:00 2001 From: Turtle Date: Mon, 26 Jul 2021 18:36:59 +0800 Subject: [PATCH] feat(mgmt): ignore emqx_dashboard API and apps API --- apps/emqx_dashboard/src/emqx_dashboard.erl | 2 +- apps/emqx_management/src/emqx_mgmt_http.erl | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/apps/emqx_dashboard/src/emqx_dashboard.erl b/apps/emqx_dashboard/src/emqx_dashboard.erl index e7b227f77..9eb1b06ac 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard.erl @@ -60,7 +60,7 @@ start_listener({Proto, Port, Options}) -> Minirest = #{ protocol => Proto, base_path => ?BASE_PATH, - apps => apps(), + modules => minirest_api:find_api_modules(apps()), authorization => Authorization, security => [#{application => []}], swagger_global_spec => GlobalSpec, diff --git a/apps/emqx_management/src/emqx_mgmt_http.erl b/apps/emqx_management/src/emqx_mgmt_http.erl index 6d768b261..8c351ae9d 100644 --- a/apps/emqx_management/src/emqx_mgmt_http.erl +++ b/apps/emqx_management/src/emqx_mgmt_http.erl @@ -54,10 +54,11 @@ start_listener({Proto, Port, Options}) -> type => apiKey, name => "authorization", in => header}}}}, + Modules = minirest_api:find_api_modules(apps()) -- [emqx_mgmt_api_apps], Minirest = #{ protocol => Proto, base_path => ?BASE_PATH, - apps => apps(), + modules => Modules, authorization => Authorization, security => [#{application => []}], swagger_global_spec => GlobalSpec}, @@ -65,15 +66,6 @@ start_listener({Proto, Port, Options}) -> {ok, _} = minirest:start(listener_name(Proto), MinirestOptions), io:format("Start ~p listener on ~p successfully.~n", [listener_name(Proto), Port]). -apps() -> - Apps = [App || {App, _, _} <- application:loaded_applications(), - case re:run(atom_to_list(App), "^emqx") of - {match,[{0,4}]} -> true; - _ -> false - end], - Plugins = lists:map(fun(Plugin) -> Plugin#plugin.name end, emqx_plugins:list()), - Apps ++ Plugins. - ranch_opts(Port, Options0) -> Options = lists:foldl( fun @@ -116,3 +108,12 @@ format({Addr, Port}) when is_list(Addr) -> io_lib:format("~s:~w", [Addr, Port]); format({Addr, Port}) when is_tuple(Addr) -> io_lib:format("~s:~w", [inet:ntoa(Addr), Port]). + +apps() -> + Apps = [App || {App, _, _} <- application:loaded_applications(), App =/= emqx_dashboard], + lists:filter(fun(App) -> + case re:run(atom_to_list(App), "^emqx") of + {match,[{0,4}]} -> true; + _ -> false + end + end, Apps).