fix(rule-engine): remove plugin_template (#4146)
chore(build): remove template plugin The template plugin is intended to work as a standalone plugin development template repo. Should not be in the umbrella project.
This commit is contained in:
parent
aadd1ba11a
commit
c30666ee26
|
@ -1,19 +0,0 @@
|
||||||
.eunit
|
|
||||||
deps
|
|
||||||
*.o
|
|
||||||
*.beam
|
|
||||||
*.plt
|
|
||||||
erl_crash.dump
|
|
||||||
ebin
|
|
||||||
rel/example_project
|
|
||||||
.concrete/DEV_MODE
|
|
||||||
.rebar
|
|
||||||
.erlang.mk/
|
|
||||||
data/
|
|
||||||
emqx_plugin_template.d
|
|
||||||
.DS_Store
|
|
||||||
erlang.mk
|
|
||||||
_build/
|
|
||||||
rebar.lock
|
|
||||||
test/ct.cover.spec
|
|
||||||
.rebar3
|
|
|
@ -1,34 +0,0 @@
|
||||||
emqx-plugin-template
|
|
||||||
====================
|
|
||||||
|
|
||||||
This is a template plugin for the EMQ X broker. And you can see [Plugin Development Guide](https://docs.emqx.io/broker/v3/en/plugins.html#plugin-development-template) to learning how to use it.
|
|
||||||
|
|
||||||
Plugin Config
|
|
||||||
-------------
|
|
||||||
|
|
||||||
Each plugin should have a 'etc/{plugin_name}.conf|config' file to store application config.
|
|
||||||
|
|
||||||
Authentication and ACL
|
|
||||||
----------------------
|
|
||||||
|
|
||||||
```
|
|
||||||
emqx:hook('client.authenticate', fun ?MODULE:on_client_authenticate/3, [Env]).
|
|
||||||
emqx:hook('client.check_acl', fun ?MODULE:on_client_check_acl/5, [Env]).
|
|
||||||
```
|
|
||||||
|
|
||||||
Plugin and Hooks
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
[Plugin Design](https://docs.emqx.io/broker/v3/en/design.html#plugin-design)
|
|
||||||
|
|
||||||
[Hooks Design](https://docs.emqx.io/broker/v3/en/design.html#hooks-design)
|
|
||||||
|
|
||||||
License
|
|
||||||
-------
|
|
||||||
|
|
||||||
Apache License Version 2.0
|
|
||||||
|
|
||||||
Author
|
|
||||||
------
|
|
||||||
|
|
||||||
EMQ X Team.
|
|
|
@ -1,3 +0,0 @@
|
||||||
1. Add a script to generate plugin project
|
|
||||||
2. Upgrade the README.md
|
|
||||||
3. Add the plugin development guide
|
|
|
@ -1,5 +0,0 @@
|
||||||
|
|
||||||
[
|
|
||||||
{emqx_plugin_template, []}
|
|
||||||
].
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
{deps, []}.
|
|
||||||
|
|
||||||
{erl_opts, [debug_info]}.
|
|
|
@ -1,26 +0,0 @@
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
%% Copyright (c) 2020 EMQ Technologies Co., Ltd. All Rights Reserved.
|
|
||||||
%%
|
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
%% you may not use this file except in compliance with the License.
|
|
||||||
%% You may obtain a copy of the License at
|
|
||||||
%%
|
|
||||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
%%
|
|
||||||
%% Unless required by applicable law or agreed to in writing, software
|
|
||||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
%% See the License for the specific language governing permissions and
|
|
||||||
%% limitations under the License.
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
|
|
||||||
-module(emqx_cli_demo).
|
|
||||||
|
|
||||||
-export([cmd/1]).
|
|
||||||
|
|
||||||
cmd(["arg1", "arg2"]) ->
|
|
||||||
emqx_ctl:print("ok");
|
|
||||||
|
|
||||||
cmd(_) ->
|
|
||||||
emqx_ctl:usage([{"cmd arg1 arg2", "cmd demo"}]).
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
{application, emqx_plugin_template,
|
|
||||||
[{description, "EMQ X Plugin Template"},
|
|
||||||
{vsn, "4.3.0"}, % strict semver, bump manually!
|
|
||||||
{modules, []},
|
|
||||||
{registered, [emqx_plugin_template_sup]},
|
|
||||||
{applications, [kernel,stdlib]},
|
|
||||||
{mod, {emqx_plugin_template_app,[]}},
|
|
||||||
{env, []},
|
|
||||||
{licenses, ["Apache-2.0"]},
|
|
||||||
{maintainers, ["EMQ X Team <contact@emqx.io>"]},
|
|
||||||
{links, [{"Homepage", "https://emqx.io/"},
|
|
||||||
{"Github", "https://github.com/emqx/emqx-plugin-template"}
|
|
||||||
]}
|
|
||||||
]}.
|
|
|
@ -1,193 +0,0 @@
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
%% Copyright (c) 2020 EMQ Technologies Co., Ltd. All Rights Reserved.
|
|
||||||
%%
|
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
%% you may not use this file except in compliance with the License.
|
|
||||||
%% You may obtain a copy of the License at
|
|
||||||
%%
|
|
||||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
%%
|
|
||||||
%% Unless required by applicable law or agreed to in writing, software
|
|
||||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
%% See the License for the specific language governing permissions and
|
|
||||||
%% limitations under the License.
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
|
|
||||||
-module(emqx_plugin_template).
|
|
||||||
|
|
||||||
-include_lib("emqx/include/emqx.hrl").
|
|
||||||
|
|
||||||
-export([ load/1
|
|
||||||
, unload/0
|
|
||||||
]).
|
|
||||||
|
|
||||||
%% Client Lifecircle Hooks
|
|
||||||
-export([ on_client_connect/3
|
|
||||||
, on_client_connack/4
|
|
||||||
, on_client_connected/3
|
|
||||||
, on_client_disconnected/4
|
|
||||||
, on_client_authenticate/3
|
|
||||||
, on_client_check_acl/5
|
|
||||||
, on_client_subscribe/4
|
|
||||||
, on_client_unsubscribe/4
|
|
||||||
]).
|
|
||||||
|
|
||||||
%% Session Lifecircle Hooks
|
|
||||||
-export([ on_session_created/3
|
|
||||||
, on_session_subscribed/4
|
|
||||||
, on_session_unsubscribed/4
|
|
||||||
, on_session_resumed/3
|
|
||||||
, on_session_discarded/3
|
|
||||||
, on_session_takeovered/3
|
|
||||||
, on_session_terminated/4
|
|
||||||
]).
|
|
||||||
|
|
||||||
%% Message Pubsub Hooks
|
|
||||||
-export([ on_message_publish/2
|
|
||||||
, on_message_delivered/3
|
|
||||||
, on_message_acked/3
|
|
||||||
, on_message_dropped/4
|
|
||||||
]).
|
|
||||||
|
|
||||||
%% Called when the plugin application start
|
|
||||||
load(Env) ->
|
|
||||||
hook('client.connect', {?MODULE, on_client_connect, [Env]}),
|
|
||||||
hook('client.connack', {?MODULE, on_client_connack, [Env]}),
|
|
||||||
hook('client.connected', {?MODULE, on_client_connected, [Env]}),
|
|
||||||
hook('client.disconnected', {?MODULE, on_client_disconnected, [Env]}),
|
|
||||||
hook('client.authenticate', {?MODULE, on_client_authenticate, [Env]}),
|
|
||||||
hook('client.check_acl', {?MODULE, on_client_check_acl, [Env]}),
|
|
||||||
hook('client.subscribe', {?MODULE, on_client_subscribe, [Env]}),
|
|
||||||
hook('client.unsubscribe', {?MODULE, on_client_unsubscribe, [Env]}),
|
|
||||||
hook('session.created', {?MODULE, on_session_created, [Env]}),
|
|
||||||
hook('session.subscribed', {?MODULE, on_session_subscribed, [Env]}),
|
|
||||||
hook('session.unsubscribed',{?MODULE, on_session_unsubscribed, [Env]}),
|
|
||||||
hook('session.resumed', {?MODULE, on_session_resumed, [Env]}),
|
|
||||||
hook('session.discarded', {?MODULE, on_session_discarded, [Env]}),
|
|
||||||
hook('session.takeovered', {?MODULE, on_session_takeovered, [Env]}),
|
|
||||||
hook('session.terminated', {?MODULE, on_session_terminated, [Env]}),
|
|
||||||
hook('message.publish', {?MODULE, on_message_publish, [Env]}),
|
|
||||||
hook('message.delivered', {?MODULE, on_message_delivered, [Env]}),
|
|
||||||
hook('message.acked', {?MODULE, on_message_acked, [Env]}),
|
|
||||||
hook('message.dropped', {?MODULE, on_message_dropped, [Env]}).
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
%% Client Lifecircle Hooks
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
|
|
||||||
on_client_connect(ConnInfo = #{clientid := ClientId}, Props, _Env) ->
|
|
||||||
io:format("Client(~s) connect, ConnInfo: ~p, Props: ~p~n",
|
|
||||||
[ClientId, ConnInfo, Props]),
|
|
||||||
{ok, Props}.
|
|
||||||
|
|
||||||
on_client_connack(ConnInfo = #{clientid := ClientId}, Rc, Props, _Env) ->
|
|
||||||
io:format("Client(~s) connack, ConnInfo: ~p, Rc: ~p, Props: ~p~n",
|
|
||||||
[ClientId, ConnInfo, Rc, Props]),
|
|
||||||
{ok, Props}.
|
|
||||||
|
|
||||||
on_client_connected(ClientInfo = #{clientid := ClientId}, ConnInfo, _Env) ->
|
|
||||||
io:format("Client(~s) connected, ClientInfo:~n~p~n, ConnInfo:~n~p~n",
|
|
||||||
[ClientId, ClientInfo, ConnInfo]).
|
|
||||||
|
|
||||||
on_client_disconnected(ClientInfo = #{clientid := ClientId}, ReasonCode, ConnInfo, _Env) ->
|
|
||||||
io:format("Client(~s) disconnected due to ~p, ClientInfo:~n~p~n, ConnInfo:~n~p~n",
|
|
||||||
[ClientId, ReasonCode, ClientInfo, ConnInfo]).
|
|
||||||
|
|
||||||
on_client_authenticate(_ClientInfo = #{clientid := ClientId}, Result, _Env) ->
|
|
||||||
io:format("Client(~s) authenticate, Result:~n~p~n", [ClientId, Result]),
|
|
||||||
{ok, Result}.
|
|
||||||
|
|
||||||
on_client_check_acl(_ClientInfo = #{clientid := ClientId}, Topic, PubSub, Result, _Env) ->
|
|
||||||
io:format("Client(~s) check_acl, PubSub:~p, Topic:~p, Result:~p~n",
|
|
||||||
[ClientId, PubSub, Topic, Result]),
|
|
||||||
{ok, Result}.
|
|
||||||
|
|
||||||
on_client_subscribe(#{clientid := ClientId}, _Properties, TopicFilters, _Env) ->
|
|
||||||
io:format("Client(~s) will subscribe: ~p~n", [ClientId, TopicFilters]),
|
|
||||||
{ok, TopicFilters}.
|
|
||||||
|
|
||||||
on_client_unsubscribe(#{clientid := ClientId}, _Properties, TopicFilters, _Env) ->
|
|
||||||
io:format("Client(~s) will unsubscribe ~p~n", [ClientId, TopicFilters]),
|
|
||||||
{ok, TopicFilters}.
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
%% Session Lifecircle Hooks
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
|
|
||||||
on_session_created(#{clientid := ClientId}, SessInfo, _Env) ->
|
|
||||||
io:format("Session(~s) created, Session Info:~n~p~n", [ClientId, SessInfo]).
|
|
||||||
|
|
||||||
on_session_subscribed(#{clientid := ClientId}, Topic, SubOpts, _Env) ->
|
|
||||||
io:format("Session(~s) subscribed ~s with subopts: ~p~n", [ClientId, Topic, SubOpts]).
|
|
||||||
|
|
||||||
on_session_unsubscribed(#{clientid := ClientId}, Topic, Opts, _Env) ->
|
|
||||||
io:format("Session(~s) unsubscribed ~s with opts: ~p~n", [ClientId, Topic, Opts]).
|
|
||||||
|
|
||||||
on_session_resumed(#{clientid := ClientId}, SessInfo, _Env) ->
|
|
||||||
io:format("Session(~s) resumed, Session Info:~n~p~n", [ClientId, SessInfo]).
|
|
||||||
|
|
||||||
on_session_discarded(_ClientInfo = #{clientid := ClientId}, SessInfo, _Env) ->
|
|
||||||
io:format("Session(~s) is discarded. Session Info: ~p~n", [ClientId, SessInfo]).
|
|
||||||
|
|
||||||
on_session_takeovered(_ClientInfo = #{clientid := ClientId}, SessInfo, _Env) ->
|
|
||||||
io:format("Session(~s) is takeovered. Session Info: ~p~n", [ClientId, SessInfo]).
|
|
||||||
|
|
||||||
on_session_terminated(_ClientInfo = #{clientid := ClientId}, Reason, SessInfo, _Env) ->
|
|
||||||
io:format("Session(~s) is terminated due to ~p~nSession Info: ~p~n",
|
|
||||||
[ClientId, Reason, SessInfo]).
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
%% Message PubSub Hooks
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
|
|
||||||
%% Transform message and return
|
|
||||||
on_message_publish(Message = #message{topic = <<"$SYS/", _/binary>>}, _Env) ->
|
|
||||||
{ok, Message};
|
|
||||||
|
|
||||||
on_message_publish(Message, _Env) ->
|
|
||||||
io:format("Publish ~s~n", [emqx_message:format(Message)]),
|
|
||||||
{ok, Message}.
|
|
||||||
|
|
||||||
on_message_dropped(#message{topic = <<"$SYS/", _/binary>>}, _By, _Reason, _Env) ->
|
|
||||||
ok;
|
|
||||||
on_message_dropped(Message, _By = #{node := Node}, Reason, _Env) ->
|
|
||||||
io:format("Message dropped by node ~s due to ~s: ~s~n",
|
|
||||||
[Node, Reason, emqx_message:format(Message)]).
|
|
||||||
|
|
||||||
on_message_delivered(_ClientInfo = #{clientid := ClientId}, Message, _Env) ->
|
|
||||||
io:format("Message delivered to client(~s): ~s~n",
|
|
||||||
[ClientId, emqx_message:format(Message)]),
|
|
||||||
{ok, Message}.
|
|
||||||
|
|
||||||
on_message_acked(_ClientInfo = #{clientid := ClientId}, Message, _Env) ->
|
|
||||||
io:format("Message acked by client(~s): ~s~n",
|
|
||||||
[ClientId, emqx_message:format(Message)]).
|
|
||||||
|
|
||||||
%% Called when the plugin application stop
|
|
||||||
unload() ->
|
|
||||||
emqx:unhook('client.connect', {?MODULE, on_client_connect}),
|
|
||||||
emqx:unhook('client.connack', {?MODULE, on_client_connack}),
|
|
||||||
emqx:unhook('client.connected', {?MODULE, on_client_connected}),
|
|
||||||
emqx:unhook('client.disconnected', {?MODULE, on_client_disconnected}),
|
|
||||||
emqx:unhook('client.authenticate', {?MODULE, on_client_authenticate}),
|
|
||||||
emqx:unhook('client.check_acl', {?MODULE, on_client_check_acl}),
|
|
||||||
emqx:unhook('client.subscribe', {?MODULE, on_client_subscribe}),
|
|
||||||
emqx:unhook('client.unsubscribe', {?MODULE, on_client_unsubscribe}),
|
|
||||||
emqx:unhook('session.created', {?MODULE, on_session_created}),
|
|
||||||
emqx:unhook('session.subscribed', {?MODULE, on_session_subscribed}),
|
|
||||||
emqx:unhook('session.unsubscribed',{?MODULE, on_session_unsubscribed}),
|
|
||||||
emqx:unhook('session.resumed', {?MODULE, on_session_resumed}),
|
|
||||||
emqx:unhook('session.discarded', {?MODULE, on_session_discarded}),
|
|
||||||
emqx:unhook('session.takeovered', {?MODULE, on_session_takeovered}),
|
|
||||||
emqx:unhook('session.terminated', {?MODULE, on_session_terminated}),
|
|
||||||
emqx:unhook('message.publish', {?MODULE, on_message_publish}),
|
|
||||||
emqx:unhook('message.delivered', {?MODULE, on_message_delivered}),
|
|
||||||
emqx:unhook('message.acked', {?MODULE, on_message_acked}),
|
|
||||||
emqx:unhook('message.dropped', {?MODULE, on_message_dropped}).
|
|
||||||
|
|
||||||
hook(Name, MFA) ->
|
|
||||||
case emqx:hook(Name, MFA) of
|
|
||||||
ok -> ok;
|
|
||||||
{error, already_exists} -> ok
|
|
||||||
end.
|
|
|
@ -1,34 +0,0 @@
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
%% Copyright (c) 2020 EMQ Technologies Co., Ltd. All Rights Reserved.
|
|
||||||
%%
|
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
%% you may not use this file except in compliance with the License.
|
|
||||||
%% You may obtain a copy of the License at
|
|
||||||
%%
|
|
||||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
%%
|
|
||||||
%% Unless required by applicable law or agreed to in writing, software
|
|
||||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
%% See the License for the specific language governing permissions and
|
|
||||||
%% limitations under the License.
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
|
|
||||||
-module(emqx_plugin_template_app).
|
|
||||||
|
|
||||||
-behaviour(application).
|
|
||||||
|
|
||||||
-emqx_plugin(?MODULE).
|
|
||||||
|
|
||||||
-export([ start/2
|
|
||||||
, stop/1
|
|
||||||
]).
|
|
||||||
|
|
||||||
start(_StartType, _StartArgs) ->
|
|
||||||
{ok, Sup} = emqx_plugin_template_sup:start_link(),
|
|
||||||
emqx_plugin_template:load(application:get_all_env()),
|
|
||||||
{ok, Sup}.
|
|
||||||
|
|
||||||
stop(_State) ->
|
|
||||||
emqx_plugin_template:unload().
|
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
%% Copyright (c) 2020 EMQ Technologies Co., Ltd. All Rights Reserved.
|
|
||||||
%%
|
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
%% you may not use this file except in compliance with the License.
|
|
||||||
%% You may obtain a copy of the License at
|
|
||||||
%%
|
|
||||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
%%
|
|
||||||
%% Unless required by applicable law or agreed to in writing, software
|
|
||||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
%% See the License for the specific language governing permissions and
|
|
||||||
%% limitations under the License.
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
|
|
||||||
-module(emqx_plugin_template_sup).
|
|
||||||
|
|
||||||
-behaviour(supervisor).
|
|
||||||
|
|
||||||
-export([start_link/0]).
|
|
||||||
|
|
||||||
-export([init/1]).
|
|
||||||
|
|
||||||
start_link() ->
|
|
||||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
|
||||||
|
|
||||||
init([]) ->
|
|
||||||
{ok, { {one_for_all, 0, 1}, []} }.
|
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
%% Copyright (c) 2020 EMQ Technologies Co., Ltd. All Rights Reserved.
|
|
||||||
%%
|
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
%% you may not use this file except in compliance with the License.
|
|
||||||
%% You may obtain a copy of the License at
|
|
||||||
%%
|
|
||||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
%%
|
|
||||||
%% Unless required by applicable law or agreed to in writing, software
|
|
||||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
%% See the License for the specific language governing permissions and
|
|
||||||
%% limitations under the License.
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
|
|
||||||
-module(emqx_plugin_template_SUITE).
|
|
||||||
|
|
||||||
-compile(nowarn_export_all).
|
|
||||||
-compile(export_all).
|
|
||||||
|
|
||||||
all() -> [].
|
|
||||||
|
|
||||||
groups() -> [].
|
|
|
@ -155,7 +155,6 @@ relx_plugin_apps_per_rel(cloud) ->
|
||||||
, emqx_exproto
|
, emqx_exproto
|
||||||
, emqx_prometheus
|
, emqx_prometheus
|
||||||
, emqx_psk_file
|
, emqx_psk_file
|
||||||
, emqx_plugin_template
|
|
||||||
];
|
];
|
||||||
relx_plugin_apps_per_rel(edge) ->
|
relx_plugin_apps_per_rel(edge) ->
|
||||||
[].
|
[].
|
||||||
|
|
|
@ -21,7 +21,6 @@ apps=(
|
||||||
"emqx_lua_hook"
|
"emqx_lua_hook"
|
||||||
"emqx_lwm2m"
|
"emqx_lwm2m"
|
||||||
"emqx_management"
|
"emqx_management"
|
||||||
"emqx_plugin_template"
|
|
||||||
"emqx_prometheus"
|
"emqx_prometheus"
|
||||||
"emqx_psk_file"
|
"emqx_psk_file"
|
||||||
"emqx_recon"
|
"emqx_recon"
|
||||||
|
|
Loading…
Reference in New Issue