exhook.proto 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) 2020-2022 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //------------------------------------------------------------------------------
  16. syntax = "proto3";
  17. option csharp_namespace = "Emqx.Exhook.V1";
  18. option go_package = "emqx.io/grpc/exhook";
  19. option java_multiple_files = true;
  20. option java_package = "io.emqx.exhook";
  21. option java_outer_classname = "EmqxExHookProto";
  22. package emqx.exhook.v1;
  23. service HookProvider {
  24. rpc OnProviderLoaded(ProviderLoadedRequest) returns (LoadedResponse) {};
  25. rpc OnProviderUnloaded(ProviderUnloadedRequest) returns (EmptySuccess) {};
  26. rpc OnClientConnect(ClientConnectRequest) returns (EmptySuccess) {};
  27. rpc OnClientConnack(ClientConnackRequest) returns (EmptySuccess) {};
  28. rpc OnClientConnected(ClientConnectedRequest) returns (EmptySuccess) {};
  29. rpc OnClientDisconnected(ClientDisconnectedRequest) returns (EmptySuccess) {};
  30. rpc OnClientAuthenticate(ClientAuthenticateRequest) returns (ValuedResponse) {};
  31. rpc OnClientAuthorize(ClientAuthorizeRequest) returns (ValuedResponse) {};
  32. rpc OnClientSubscribe(ClientSubscribeRequest) returns (EmptySuccess) {};
  33. rpc OnClientUnsubscribe(ClientUnsubscribeRequest) returns (EmptySuccess) {};
  34. rpc OnSessionCreated(SessionCreatedRequest) returns (EmptySuccess) {};
  35. rpc OnSessionSubscribed(SessionSubscribedRequest) returns (EmptySuccess) {};
  36. rpc OnSessionUnsubscribed(SessionUnsubscribedRequest) returns (EmptySuccess) {};
  37. rpc OnSessionResumed(SessionResumedRequest) returns (EmptySuccess) {};
  38. rpc OnSessionDiscarded(SessionDiscardedRequest) returns (EmptySuccess) {};
  39. rpc OnSessionTakenover(SessionTakenoverRequest) returns (EmptySuccess) {};
  40. rpc OnSessionTerminated(SessionTerminatedRequest) returns (EmptySuccess) {};
  41. rpc OnMessagePublish(MessagePublishRequest) returns (ValuedResponse) {};
  42. rpc OnMessageDelivered(MessageDeliveredRequest) returns (EmptySuccess) {};
  43. rpc OnMessageDropped(MessageDroppedRequest) returns (EmptySuccess) {};
  44. rpc OnMessageAcked(MessageAckedRequest) returns (EmptySuccess) {};
  45. }
  46. //------------------------------------------------------------------------------
  47. // Request & Response
  48. //------------------------------------------------------------------------------
  49. message ProviderLoadedRequest {
  50. BrokerInfo broker = 1;
  51. }
  52. message LoadedResponse {
  53. repeated HookSpec hooks = 1;
  54. }
  55. message ProviderUnloadedRequest { }
  56. message ClientConnectRequest {
  57. ConnInfo conninfo = 1;
  58. // MQTT CONNECT packet's properties (MQTT v5.0)
  59. //
  60. // It should be empty on MQTT v3.1.1/v3.1 or others protocol
  61. repeated Property props = 2;
  62. }
  63. message ClientConnackRequest {
  64. ConnInfo conninfo = 1;
  65. string result_code = 2;
  66. repeated Property props = 3;
  67. }
  68. message ClientConnectedRequest {
  69. ClientInfo clientinfo = 1;
  70. }
  71. message ClientDisconnectedRequest {
  72. ClientInfo clientinfo = 1;
  73. string reason = 2;
  74. }
  75. message ClientAuthenticateRequest {
  76. ClientInfo clientinfo = 1;
  77. bool result = 2;
  78. }
  79. message ClientAuthorizeRequest {
  80. ClientInfo clientinfo = 1;
  81. enum AuthorizeReqType {
  82. PUBLISH = 0;
  83. SUBSCRIBE = 1;
  84. }
  85. AuthorizeReqType type = 2;
  86. string topic = 3;
  87. bool result = 4;
  88. }
  89. message ClientSubscribeRequest {
  90. ClientInfo clientinfo = 1;
  91. repeated Property props = 2;
  92. repeated TopicFilter topic_filters = 3;
  93. }
  94. message ClientUnsubscribeRequest {
  95. ClientInfo clientinfo = 1;
  96. repeated Property props = 2;
  97. repeated TopicFilter topic_filters = 3;
  98. }
  99. message SessionCreatedRequest {
  100. ClientInfo clientinfo = 1;
  101. }
  102. message SessionSubscribedRequest {
  103. ClientInfo clientinfo = 1;
  104. string topic = 2;
  105. SubOpts subopts = 3;
  106. }
  107. message SessionUnsubscribedRequest {
  108. ClientInfo clientinfo = 1;
  109. string topic = 2;
  110. }
  111. message SessionResumedRequest {
  112. ClientInfo clientinfo = 1;
  113. }
  114. message SessionDiscardedRequest {
  115. ClientInfo clientinfo = 1;
  116. }
  117. message SessionTakenoverRequest {
  118. ClientInfo clientinfo = 1;
  119. }
  120. message SessionTerminatedRequest {
  121. ClientInfo clientinfo = 1;
  122. string reason = 2;
  123. }
  124. message MessagePublishRequest {
  125. Message message = 1;
  126. }
  127. message MessageDeliveredRequest {
  128. ClientInfo clientinfo = 1;
  129. Message message = 2;
  130. }
  131. message MessageDroppedRequest {
  132. Message message = 1;
  133. string reason = 2;
  134. }
  135. message MessageAckedRequest {
  136. ClientInfo clientinfo = 1;
  137. Message message = 2;
  138. }
  139. //------------------------------------------------------------------------------
  140. // Basic data types
  141. //------------------------------------------------------------------------------
  142. message EmptySuccess { }
  143. message ValuedResponse {
  144. // The responsed value type
  145. // - contiune: Use the responsed value and execute the next hook
  146. // - ignore: Ignore the responsed value
  147. // - stop_and_return: Use the responsed value and stop the chain executing
  148. enum ResponsedType {
  149. CONTINUE = 0;
  150. IGNORE = 1;
  151. STOP_AND_RETURN = 2;
  152. }
  153. ResponsedType type = 1;
  154. oneof value {
  155. // Boolean result, used on the 'client.authenticate', 'client.authorize' hooks
  156. bool bool_result = 3;
  157. // Message result, used on the 'message.*' hooks
  158. Message message = 4;
  159. }
  160. }
  161. message BrokerInfo {
  162. string version = 1;
  163. string sysdescr = 2;
  164. int64 uptime = 3;
  165. string datetime = 4;
  166. }
  167. message HookSpec {
  168. // The registered hooks name
  169. //
  170. // Available value:
  171. // "client.connect", "client.connack"
  172. // "client.connected", "client.disconnected"
  173. // "client.authenticate", "client.authorize"
  174. // "client.subscribe", "client.unsubscribe"
  175. //
  176. // "session.created", "session.subscribed"
  177. // "session.unsubscribed", "session.resumed"
  178. // "session.discarded", "session.takenover"
  179. // "session.terminated"
  180. //
  181. // "message.publish", "message.delivered"
  182. // "message.acked", "message.dropped"
  183. string name = 1;
  184. // The topic filters for message hooks
  185. repeated string topics = 2;
  186. }
  187. message ConnInfo {
  188. string node = 1;
  189. string clientid = 2;
  190. string username = 3;
  191. string peerhost = 4;
  192. uint32 sockport = 5;
  193. string proto_name = 6;
  194. string proto_ver = 7;
  195. uint32 keepalive = 8;
  196. }
  197. message ClientInfo {
  198. string node = 1;
  199. string clientid = 2;
  200. string username = 3;
  201. string password = 4;
  202. string peerhost = 5;
  203. uint32 sockport = 6;
  204. string protocol = 7;
  205. string mountpoint = 8;
  206. bool is_superuser = 9;
  207. bool anonymous = 10;
  208. // common name of client TLS cert
  209. string cn = 11;
  210. // subject of client TLS cert
  211. string dn = 12;
  212. }
  213. message Message {
  214. string node = 1;
  215. string id = 2;
  216. uint32 qos = 3;
  217. string from = 4;
  218. string topic = 5;
  219. bytes payload = 6;
  220. uint64 timestamp = 7;
  221. // The key of header can be:
  222. // - username:
  223. // * Readonly
  224. // * The username of sender client
  225. // * Value type: utf8 string
  226. // - protocol:
  227. // * Readonly
  228. // * The protocol name of sender client
  229. // * Value type: string enum with "mqtt", "mqtt-sn", ...
  230. // - peerhost:
  231. // * Readonly
  232. // * The peerhost of sender client
  233. // * Value type: ip address string
  234. // - allow_publish:
  235. // * Writable
  236. // * Whether to allow the message to be published by emqx
  237. // * Value type: string enum with "true", "false", default is "true"
  238. //
  239. // Notes: All header may be missing, which means that the message does not
  240. // carry these headers. We can guarantee that clients coming from MQTT,
  241. // MQTT-SN, CoAP, LwM2M and other natively supported protocol clients will
  242. // carry these headers, but there is no guarantee that messages published
  243. // by other means will do, e.g. messages published by HTTP-API
  244. map<string, string> headers = 8;
  245. }
  246. message Property {
  247. string name = 1;
  248. string value = 2;
  249. }
  250. message TopicFilter {
  251. string name = 1;
  252. uint32 qos = 2;
  253. }
  254. message SubOpts {
  255. // The QoS level
  256. uint32 qos = 1;
  257. // The group name for shared subscription
  258. string share = 2;
  259. // The Retain Handling option (MQTT v5.0)
  260. //
  261. // 0 = Send retained messages at the time of the subscribe
  262. // 1 = Send retained messages at subscribe only if the subscription does
  263. // not currently exist
  264. // 2 = Do not send retained messages at the time of the subscribe
  265. uint32 rh = 3;
  266. // The Retain as Published option (MQTT v5.0)
  267. //
  268. // If 1, Application Messages forwarded using this subscription keep the
  269. // RETAIN flag they were published with.
  270. // If 0, Application Messages forwarded using this subscription have the
  271. // RETAIN flag set to 0.
  272. // Retained messages sent when the subscription is established have the RETAIN flag set to 1.
  273. uint32 rap = 4;
  274. // The No Local option (MQTT v5.0)
  275. //
  276. // If the value is 1, Application Messages MUST NOT be forwarded to a
  277. // connection with a ClientID equal to the ClientID of the publishing
  278. uint32 nl = 5;
  279. }