Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions emqx-plugin-templates/rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
%% -*- mode: erlang -*-
{deps, [
{emqx_plugin_helper,
{git, "https://github.com/emqx/emqx-plugin-helper.git", {tag, "v5.9.0"}}},
{git, "https://github.com/emqx/emqx-plugin-helper.git", {tag, "@@emqx_plugin_helper_vsn@@"}}},
%% this is my plugin's dependency
{map_sets, "1.1.0"}
]}.

{plugins, [
{emqx_plugin_helper,
{git, "https://github.com/emqx/emqx-plugin-helper.git", {tag, "v5.9.0"}}},
{git, "https://github.com/emqx/emqx-plugin-helper.git", {tag, "@@emqx_plugin_helper_vsn@@"}}},
{erlfmt, "1.6.0"}
]}.

Expand Down
9 changes: 7 additions & 2 deletions emqx-plugin-templates/src/emqx_plugin_template.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-module(@@name@@).

-define(PLUGIN_NAME, "@@name@@").
-define(PLUGIN_VSN, "1.0.0").
-define(PLUGIN_VSN, "@@version@@").

%% for #message{} record
%% no need for this include if we call emqx_message:to_map/1 to convert it to a map
Expand Down Expand Up @@ -116,6 +116,8 @@ on_client_connect(ConnInfo, Props, some_arg) ->
{ok, Props}.

%% @doc
%% This a fold hook callback.
%%
%% - Return `{stop, ok}' if this client is to be allowed to login.
%% - Return `{stop, {error, not_authorized}}' if this client is not allowed to login.
%% - Return `ignore' if this client is to be authenticated by other plugins
Expand All @@ -136,6 +138,8 @@ on_client_authenticate(#{clientid := ClientId} = _ClientInfo, DefaultResult) ->
end.

%% @doc
%% This is a fold hook callback.
%%
%% - To permit/forbid actions, return `{stop, #{result => Result}}' where `Result' is either `allow' or `deny'.
%% - Return `ignore' if this client is to be authorized by other plugins or
%% EMQX's built-in authorization sources.
Expand Down Expand Up @@ -165,7 +169,7 @@ on_client_authorize(_ClientInfo = #{clientid := ClientId}, Action, Topic, _Resul
ignore.

%% @doc
%% Demo callback working with messages.
%% Demo callback working with messages. This is a fold hook callback.
on_message_puback(_PacketId, #message{} = Message, PubRes, RC) ->
NewRC =
case RC of
Expand Down Expand Up @@ -268,4 +272,5 @@ handle_info(_Request, State) ->
{noreply, State}.

terminate(_Reason, _State) ->
persistent_term:erase(?MODULE),
ok.
2 changes: 1 addition & 1 deletion emqx-plugin.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{description, "Another amazing EMQX plugin."},
{version, "1.0.0", "The release version of this plugin."},
{app_vsn, "0.1.0", "The erlang application vsn value."},
{emqx_vsn, "e5.9.0-beta.1", "EMQX version to use as a dependency."},
{emqx_plugin_helper_vsn, "v5.9.0", "EMQX Plugin helper to use as a dependency."},
{license, "Apache-2.0", "Short identifier for license you want to distribute this plugin under."},
{author_website, "http://example.com", "A website with details about the author."},
{repo, "https://github.com/emqx/emqx-plugin-template", "Where to find the source code for this plugin."}
Expand Down