Add plugin type

This commit is contained in:
turtled 2019-06-21 14:09:41 +08:00 committed by turtleDeng
parent 0c7c4ee417
commit 481458d8ec
2 changed files with 13 additions and 5 deletions

View File

@ -132,7 +132,8 @@
descr :: string(), descr :: string(),
vendor :: string(), vendor :: string(),
active = false :: boolean(), active = false :: boolean(),
info :: map() info :: map(),
type :: atom()
}). }).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------

View File

@ -151,20 +151,20 @@ stop_plugins(Names) ->
-spec(list() -> [emqx_types:plugin()]). -spec(list() -> [emqx_types:plugin()]).
list() -> list() ->
StartedApps = names(started_app), StartedApps = names(started_app),
lists:map(fun({Name, _, _}) -> lists:map(fun({Name, _, [Type| _]}) ->
Plugin = plugin(Name), Plugin = plugin(Name, Type),
case lists:member(Name, StartedApps) of case lists:member(Name, StartedApps) of
true -> Plugin#plugin{active = true}; true -> Plugin#plugin{active = true};
false -> Plugin false -> Plugin
end end
end, lists:sort(ekka_boot:all_module_attributes(emqx_plugin))). end, lists:sort(ekka_boot:all_module_attributes(emqx_plugin))).
plugin(AppName) -> plugin(AppName, Type) ->
case application:get_all_key(AppName) of case application:get_all_key(AppName) of
{ok, Attrs} -> {ok, Attrs} ->
Ver = proplists:get_value(vsn, Attrs, "0"), Ver = proplists:get_value(vsn, Attrs, "0"),
Descr = proplists:get_value(description, Attrs, ""), Descr = proplists:get_value(description, Attrs, ""),
#plugin{name = AppName, version = Ver, descr = Descr}; #plugin{name = AppName, version = Ver, descr = Descr, type = plugin_type(Type)};
undefined -> error({plugin_not_found, AppName}) undefined -> error({plugin_not_found, AppName})
end. end.
@ -316,3 +316,10 @@ write_loaded(AppNames) ->
?LOG(error, "Open File ~p Error: ~p", [File, Error]), ?LOG(error, "Open File ~p Error: ~p", [File, Error]),
{error, Error} {error, Error}
end. end.
plugin_type(auth) -> auth;
plugin_type(protocol) -> protocol;
plugin_type(backend) -> backend;
plugin_type(bridge) -> bridge;
plugin_type(_) -> feature.