Просмотр исходного кода

fix(emqx_rule_api_schema): add rule events schema

EMQ-YangM 3 лет назад
Родитель
Сommit
ccc134d061

+ 27 - 0
apps/emqx_rule_engine/src/emqx_rule_api_schema.erl

@@ -73,6 +73,8 @@ fields("rule_test") ->
                                    , ref("ctx_dropped")
                                    , ref("ctx_connected")
                                    , ref("ctx_disconnected")
+                                   , ref("ctx_connack")
+                                   , ref("ctx_check_authz_complete")
                                    , ref("ctx_bridge_mqtt")
                                    ]),
         #{desc => "The context of the event for testing",
@@ -208,6 +210,31 @@ fields("ctx_disconnected") ->
         desc => "The Time that this Client is Disconnected"})}
     ];
 
+fields("ctx_connack") ->
+    [ {"event_type", sc(client_connack, #{desc => "Event Type", required => true})}
+    , {"reason_code", sc(binary(), #{desc => "The reason code"})}
+    , {"clientid", sc(binary(), #{desc => "The Client ID"})}
+    , {"clean_start", sc(boolean(), #{desc => "Clean Start", default => true})}
+    , {"username", sc(binary(), #{desc => "The User Name"})}
+    , {"peername", sc(binary(), #{desc => "The IP Address and Port of the Peer Client"})}
+    , {"sockname", sc(binary(), #{desc => "The IP Address and Port of the Local Listener"})}
+    , {"proto_name", sc(binary(), #{desc => "Protocol Name"})}
+    , {"proto_ver", sc(binary(), #{desc => "Protocol Version"})}
+    , {"keepalive", sc(integer(), #{desc => "KeepAlive"})}
+    , {"expiry_interval", sc(integer(), #{desc => "Expiry Interval"})}
+    , {"connected_at", sc(integer(), #{
+        desc => "The Time that this Client is Connected"})}
+    ];
+fields("ctx_check_authz_complete") ->
+    [ {"event_type", sc(client_check_authz_complete, #{desc => "Event Type", required => true})}
+    , {"clientid", sc(binary(), #{desc => "The Client ID"})}
+    , {"username", sc(binary(), #{desc => "The User Name"})}
+    , {"peerhost", sc(binary(), #{desc => "The IP Address of the Peer Client"})}
+    , {"topic", sc(binary(), #{desc => "Message Topic"})}
+    , {"action", sc(binary(), #{desc => "Publish or Subscribe"})}
+    , {"authz_source", sc(binary(), #{desc => "Cache, Plugs or Default"})}
+    , {"result", sc(binary(), #{desc => "Allow or Deny"})}
+    ];
 fields("ctx_bridge_mqtt") ->
     [ {"event_type", sc('$bridges/mqtt:*', #{desc => "Event Type", required => true})}
     , {"id", sc(binary(), #{desc => "Message ID"})}

+ 8 - 8
apps/emqx_rule_engine/src/emqx_rule_events.erl

@@ -576,16 +576,16 @@ test_columns('client.disconnected') ->
     , {<<"reason">>, [<<"normal">>, <<"the reason for shutdown">>]}
     ];
 test_columns('client.connack') ->
-    [ {<<"clientid">>, <<"c_emqx">>}
-    , {<<"username">>, <<"u_emqx">>}
-    , {<<"reason_code">>, <<"sucess">>}
+    [ {<<"clientid">>, [<<"c_emqx">>, <<"the clientid if the client">>]}
+    , {<<"username">>, [<<"u_emqx">>, <<"the username if the client">>]}
+    , {<<"reason_code">>, [<<"sucess">>, <<"the reason code">>]}
     ];
 test_columns('client.check_authz_complete') ->
-    [ {<<"clientid">>, <<"c_emqx">>}
-    , {<<"username">>, <<"u_emqx">>}
-    , {<<"topic">>, <<"t/1">>}
-    , {<<"action">>, <<"publish">>}
-    , {<<"result">>, <<"allow">>}
+    [ {<<"clientid">>, [<<"c_emqx">>, <<"the clientid if the client">>]}
+    , {<<"username">>, [<<"u_emqx">>, <<"the username if the client">>]}
+    , {<<"topic">>,    [<<"t/1">>, <<"the topic of the MQTT message">>]}
+    , {<<"action">>,   [<<"publish">>, <<"the action of publish or subscribe">>]}
+    , {<<"result">>,   [<<"allow">>,<<"the authz check complete result">>]}
     ];
 test_columns('session.unsubscribed') ->
     test_columns('session.subscribed');

+ 0 - 1
apps/emqx_rule_engine/test/emqx_rule_engine_SUITE.erl

@@ -1703,7 +1703,6 @@ verify_event_fields('client.check_authz_complete', Fields) ->
     ?assert(lists:member(ClientId, [<<"c_event">>, <<"c_event2">>])),
     ?assert(lists:member(Username, [<<"u_event">>, <<"u_event2">>])).
 
-
 verify_peername(PeerName) ->
     case string:split(PeerName, ":") of
         [IPAddrS, PortS] ->