exhook.proto 10 KB

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