feat(emqx_rule_events): add field 'is_cache'
This commit is contained in:
parent
44f4dfa498
commit
059fc6e3c7
|
@ -39,7 +39,7 @@
|
|||
, on_message_delivered/3
|
||||
, on_message_acked/3
|
||||
, on_delivery_dropped/4
|
||||
, on_client_check_acl_complete/5
|
||||
, on_client_check_acl_complete/6
|
||||
]).
|
||||
|
||||
-export([ event_info/0
|
||||
|
@ -114,12 +114,13 @@ on_client_connack(ConnInfo, Reason, _, Env) ->
|
|||
may_publish_and_apply('client.connack',
|
||||
fun() -> eventmsg_connack(ConnInfo, Reason) end, Env).
|
||||
|
||||
on_client_check_acl_complete(ClientInfo, PubSub, Topic, Result, Env) ->
|
||||
on_client_check_acl_complete(ClientInfo, PubSub, Topic, Result, IsCache, Env) ->
|
||||
may_publish_and_apply('client.check_acl_complete',
|
||||
fun() -> eventmsg_check_acl_complete(ClientInfo,
|
||||
PubSub,
|
||||
Topic,
|
||||
Result) end, Env).
|
||||
Result,
|
||||
IsCache) end, Env).
|
||||
|
||||
on_session_subscribed(ClientInfo, Topic, SubOpts, Env) ->
|
||||
may_publish_and_apply('session.subscribed',
|
||||
|
@ -266,13 +267,14 @@ eventmsg_check_acl_complete(_ClientInfo = #{
|
|||
clientid := ClientId,
|
||||
username := Username,
|
||||
peerhost := PeerHost
|
||||
}, PubSub, Topic, Result) ->
|
||||
}, PubSub, Topic, Result, IsCache) ->
|
||||
with_basic_columns('client.check_acl_complete',
|
||||
#{clientid => ClientId,
|
||||
username => Username,
|
||||
peerhost => ntoa(PeerHost),
|
||||
topic => Topic,
|
||||
action => PubSub,
|
||||
is_cache => IsCache,
|
||||
result => Result
|
||||
}).
|
||||
|
||||
|
@ -737,6 +739,7 @@ columns_with_exam('client.check_acl_complete') ->
|
|||
, {<<"peerhost">>, <<"192.168.0.10">>}
|
||||
, {<<"topic">>, <<"t/a">>}
|
||||
, {<<"action">>, <<"publish">>}
|
||||
, {<<"is_cache">>, <<"false">>}
|
||||
, {<<"result">>, <<"allow">>}
|
||||
, {<<"timestamp">>, erlang:system_time(millisecond)}
|
||||
, {<<"node">>, node()}
|
||||
|
|
|
@ -2809,11 +2809,13 @@ verify_event_fields('client.check_acl_complete', Fields) ->
|
|||
action := Action,
|
||||
result := Result,
|
||||
topic := Topic,
|
||||
is_cache := IsCache,
|
||||
username := Username
|
||||
} = Fields,
|
||||
?assertEqual(<<"t1">>, Topic),
|
||||
?assert(lists:member(Action, [subscribe, publish])),
|
||||
?assert(lists:member(Result, [allow, deny])),
|
||||
?assert(lists:member(IsCache, [true, false])),
|
||||
?assert(lists:member(ClientId, [<<"c_event">>, <<"c_event2">>])),
|
||||
?assert(lists:member(Username, [<<"u_event">>, <<"u_event2">>])).
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ check_acl(ClientInfo, PubSub, Topic) ->
|
|||
false -> do_check_acl(ClientInfo, PubSub, Topic)
|
||||
end,
|
||||
inc_acl_metrics(Result),
|
||||
emqx:run_hook('client.check_acl_complete', [ClientInfo, PubSub, Topic, Result]),
|
||||
Result.
|
||||
|
||||
check_acl_cache(ClientInfo, PubSub, Topic) ->
|
||||
|
@ -61,15 +60,18 @@ check_acl_cache(ClientInfo, PubSub, Topic) ->
|
|||
AclResult;
|
||||
AclResult ->
|
||||
inc_acl_metrics(cache_hit),
|
||||
emqx:run_hook('client.check_acl_complete', [ClientInfo, PubSub, Topic, AclResult, true]),
|
||||
AclResult
|
||||
end.
|
||||
|
||||
do_check_acl(ClientInfo = #{zone := Zone}, PubSub, Topic) ->
|
||||
Default = emqx_zone:get_env(Zone, acl_nomatch, deny),
|
||||
case run_hooks('client.check_acl', [ClientInfo, PubSub, Topic], Default) of
|
||||
Result = case run_hooks('client.check_acl', [ClientInfo, PubSub, Topic], Default) of
|
||||
allow -> allow;
|
||||
_Other -> deny
|
||||
end.
|
||||
end,
|
||||
emqx:run_hook('client.check_acl_complete', [ClientInfo, PubSub, Topic, Result, false]),
|
||||
Result.
|
||||
|
||||
default_auth_result(Zone) ->
|
||||
case emqx_zone:get_env(Zone, allow_anonymous, false) of
|
||||
|
|
Loading…
Reference in New Issue