From 4d91b5cb69c1ca02eecbd35884ab12d772bd04f8 Mon Sep 17 00:00:00 2001 From: JianBo He Date: Mon, 3 Jul 2023 11:05:03 +0800 Subject: [PATCH 1/2] chore: enhance the README for exhook-svr-python --- exhook-svr-python/.gitignore | 2 - exhook-svr-python/README.md | 88 +++- exhook-svr-python/exhook_pb2.py | 101 ++++ exhook-svr-python/exhook_pb2_grpc.py | 726 +++++++++++++++++++++++++++ exhook-svr-python/exhook_server.py | 6 +- 5 files changed, 914 insertions(+), 9 deletions(-) create mode 100644 exhook-svr-python/exhook_pb2.py create mode 100644 exhook-svr-python/exhook_pb2_grpc.py diff --git a/exhook-svr-python/.gitignore b/exhook-svr-python/.gitignore index aaafd0d..bee8a64 100644 --- a/exhook-svr-python/.gitignore +++ b/exhook-svr-python/.gitignore @@ -1,3 +1 @@ __pycache__ -exhook_pb2.py -exhook_pb2_grpc.py diff --git a/exhook-svr-python/README.md b/exhook-svr-python/README.md index 5409566..ebbb593 100644 --- a/exhook-svr-python/README.md +++ b/exhook-svr-python/README.md @@ -6,23 +6,99 @@ This is a demo server written in python for exhook - [Python](https://www.python.org) 3.5 or higher - pip version 9.0.1 or higher +- EMQX 5.0 or above -## Run +### Install gRPC and gRPC tools -Install gRPC and gRPC Tools: +Before running, we need to install the following dependencies related to gRPC: ``` python -m pip install grpcio python -m pip install grpcio-tools ``` -Try to compile the `*.proto` files: +## Test it with EMQX + +1. Make sure that EMQX is version 5.0 or above. +2. Run the ExHook server by the following command: ``` -python -m grpc_tools.protoc -I./protos --python_out=. --grpc_python_out=. ./protos/exhook.proto +python exhook_server.py ``` +3. Add an ExHook Server through the EMQX Dashboard and ensure that its address points to this example program. you can refer to the [Offcial Documentation](https://docs.emqx.com/en/enterprise/v5.1/extensions/exhook.html) -Run server: +4. Observing this example program, it will print that it has received the `OnProviderLoaded` callback, indicating that they have successfully established a connection. ``` -python exhook_server.py +OnProviderLoaded: broker { + version: "5.1.0" + sysdescr: "EMQX" + uptime: 67553173 + datetime: "2023-07-01T02:03:24.826755959+00:00" +} +... +``` + +5. Use an MQTT client, such as [MQTTX](https://mqttx.app/), to connect to EMQX and + observe the output of this example program. e.g: + +``` +OnClientConnect: ... +OnClientAuthenticate: ... +OnSessionCreated: ... +OnClientConnected: ... +OnClientConnack: ... ``` + +At this point, the example program has successfully integrated with EMQX. + +## Modify the exhook_server.py to deny all MQTT connecting request + +In this section, we will take the `OnClientAuthenticate` callback as an example and +attempt to modify its implementation in `exhook_server.py` to deny some MQTT client +connections. + +1. Modify the `OnClientAuthenticate` function in `exhook_server.py` to reject all + client logins with the username "baduser". + The complete implementation of the modified function is as follows: +``` +def OnClientAuthenticate(self, request, context): + print("OnClientAuthenticate:", request) + clientinfo = request.clientinfo + if clientinfo.username == "baduser": + reply = exhook_pb2.ValuedResponse(type="STOP_AND_RETURN", bool_result=False) + else: + reply = exhook_pb2.ValuedResponse(type="STOP_AND_RETURN", bool_result=True) + return reply +``` + +2. Shutdown and restart `exhook_server.py`. + +3. Set the username of the MQTT client to "baduser" and connect to EMQX to test. + +4. It can be observed that the client is unable to connect due to authentication failure, and the `exhook_server.py` will also output similar logs like this: +``` +OnClientConnect: ... +OnClientAuthenticate: ... +OnClientConnack: ... +result_code: "not_authorized" +... +``` + +## Update the exhook.proto to latest version + +Due to the inconsistency between the exhook.proto file used in this demo and the one included +in your installed version of EMQX, you may need to ensure their consistency. + +For example, in EMQX v5.1.0, this file is located at +https://github.com/emqx/emqx/blob/v5.1.0/apps/emqx_exhook/priv/protos/exhook.proto + +You need to manually update it to the `protos/exproto.proto` location and +regenerate code via the following command: + +``` +python -m grpc_tools.protoc -I./protos --python_out=. --grpc_python_out=. ./protos/exhook.proto +``` + +## References + +- [gRPC.io Python Quick start](https://grpc.io/docs/languages/python/quickstart/) diff --git a/exhook-svr-python/exhook_pb2.py b/exhook-svr-python/exhook_pb2.py new file mode 100644 index 0000000..e340a6b --- /dev/null +++ b/exhook-svr-python/exhook_pb2.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: exhook.proto +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0c\x65xhook.proto\x12\x0e\x65mqx.exhook.v2\"n\n\x15ProviderLoadedRequest\x12*\n\x06\x62roker\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.BrokerInfo\x12)\n\x04meta\x18\x02 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"D\n\x17ProviderUnloadedRequest\x12)\n\x04meta\x18\x01 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"\x96\x01\n\x14\x43lientConnectRequest\x12*\n\x08\x63onninfo\x18\x01 \x01(\x0b\x32\x18.emqx.exhook.v2.ConnInfo\x12\'\n\x05props\x18\x02 \x03(\x0b\x32\x18.emqx.exhook.v2.Property\x12)\n\x04meta\x18\x03 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"\xab\x01\n\x14\x43lientConnackRequest\x12*\n\x08\x63onninfo\x18\x01 \x01(\x0b\x32\x18.emqx.exhook.v2.ConnInfo\x12\x13\n\x0bresult_code\x18\x02 \x01(\t\x12\'\n\x05props\x18\x03 \x03(\x0b\x32\x18.emqx.exhook.v2.Property\x12)\n\x04meta\x18\x04 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"s\n\x16\x43lientConnectedRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12)\n\x04meta\x18\x02 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"\x86\x01\n\x19\x43lientDisconnectedRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12\x0e\n\x06reason\x18\x02 \x01(\t\x12)\n\x04meta\x18\x03 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"\x86\x01\n\x19\x43lientAuthenticateRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12\x0e\n\x06result\x18\x02 \x01(\x08\x12)\n\x04meta\x18\x03 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"\x89\x02\n\x16\x43lientAuthorizeRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12\x45\n\x04type\x18\x02 \x01(\x0e\x32\x37.emqx.exhook.v2.ClientAuthorizeRequest.AuthorizeReqType\x12\r\n\x05topic\x18\x03 \x01(\t\x12\x0e\n\x06result\x18\x04 \x01(\x08\x12)\n\x04meta\x18\x05 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\".\n\x10\x41uthorizeReqType\x12\x0b\n\x07PUBLISH\x10\x00\x12\r\n\tSUBSCRIBE\x10\x01\"\xd0\x01\n\x16\x43lientSubscribeRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12\'\n\x05props\x18\x02 \x03(\x0b\x32\x18.emqx.exhook.v2.Property\x12\x32\n\rtopic_filters\x18\x03 \x03(\x0b\x32\x1b.emqx.exhook.v2.TopicFilter\x12)\n\x04meta\x18\x04 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"\xd2\x01\n\x18\x43lientUnsubscribeRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12\'\n\x05props\x18\x02 \x03(\x0b\x32\x18.emqx.exhook.v2.Property\x12\x32\n\rtopic_filters\x18\x03 \x03(\x0b\x32\x1b.emqx.exhook.v2.TopicFilter\x12)\n\x04meta\x18\x04 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"r\n\x15SessionCreatedRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12)\n\x04meta\x18\x02 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"\xae\x01\n\x18SessionSubscribedRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12\r\n\x05topic\x18\x02 \x01(\t\x12(\n\x07subopts\x18\x03 \x01(\x0b\x32\x17.emqx.exhook.v2.SubOpts\x12)\n\x04meta\x18\x04 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"\x86\x01\n\x1aSessionUnsubscribedRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12\r\n\x05topic\x18\x02 \x01(\t\x12)\n\x04meta\x18\x03 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"r\n\x15SessionResumedRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12)\n\x04meta\x18\x02 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"t\n\x17SessionDiscardedRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12)\n\x04meta\x18\x02 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"t\n\x17SessionTakenoverRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12)\n\x04meta\x18\x02 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"\x85\x01\n\x18SessionTerminatedRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12\x0e\n\x06reason\x18\x02 \x01(\t\x12)\n\x04meta\x18\x03 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"l\n\x15MessagePublishRequest\x12(\n\x07message\x18\x01 \x01(\x0b\x32\x17.emqx.exhook.v2.Message\x12)\n\x04meta\x18\x02 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"\x9e\x01\n\x17MessageDeliveredRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12(\n\x07message\x18\x02 \x01(\x0b\x32\x17.emqx.exhook.v2.Message\x12)\n\x04meta\x18\x03 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"|\n\x15MessageDroppedRequest\x12(\n\x07message\x18\x01 \x01(\x0b\x32\x17.emqx.exhook.v2.Message\x12\x0e\n\x06reason\x18\x02 \x01(\t\x12)\n\x04meta\x18\x03 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"\x9a\x01\n\x13MessageAckedRequest\x12.\n\nclientinfo\x18\x01 \x01(\x0b\x32\x1a.emqx.exhook.v2.ClientInfo\x12(\n\x07message\x18\x02 \x01(\x0b\x32\x17.emqx.exhook.v2.Message\x12)\n\x04meta\x18\x03 \x01(\x0b\x32\x1b.emqx.exhook.v2.RequestMeta\"9\n\x0eLoadedResponse\x12\'\n\x05hooks\x18\x01 \x03(\x0b\x32\x18.emqx.exhook.v2.HookSpec\"\xd8\x01\n\x0eValuedResponse\x12:\n\x04type\x18\x01 \x01(\x0e\x32,.emqx.exhook.v2.ValuedResponse.ResponsedType\x12\x15\n\x0b\x62ool_result\x18\x03 \x01(\x08H\x00\x12*\n\x07message\x18\x04 \x01(\x0b\x32\x17.emqx.exhook.v2.MessageH\x00\">\n\rResponsedType\x12\x0c\n\x08\x43ONTINUE\x10\x00\x12\n\n\x06IGNORE\x10\x01\x12\x13\n\x0fSTOP_AND_RETURN\x10\x02\x42\x07\n\x05value\"\x0e\n\x0c\x45mptySuccess\"Q\n\nBrokerInfo\x12\x0f\n\x07version\x18\x01 \x01(\t\x12\x10\n\x08sysdescr\x18\x02 \x01(\t\x12\x0e\n\x06uptime\x18\x03 \x01(\x03\x12\x10\n\x08\x64\x61tetime\x18\x04 \x01(\t\"(\n\x08HookSpec\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0e\n\x06topics\x18\x02 \x03(\t\"\x9a\x01\n\x08\x43onnInfo\x12\x0c\n\x04node\x18\x01 \x01(\t\x12\x10\n\x08\x63lientid\x18\x02 \x01(\t\x12\x10\n\x08username\x18\x03 \x01(\t\x12\x10\n\x08peerhost\x18\x04 \x01(\t\x12\x10\n\x08sockport\x18\x05 \x01(\r\x12\x12\n\nproto_name\x18\x06 \x01(\t\x12\x11\n\tproto_ver\x18\x07 \x01(\t\x12\x11\n\tkeepalive\x18\x08 \x01(\r\"\xdb\x01\n\nClientInfo\x12\x0c\n\x04node\x18\x01 \x01(\t\x12\x10\n\x08\x63lientid\x18\x02 \x01(\t\x12\x10\n\x08username\x18\x03 \x01(\t\x12\x10\n\x08password\x18\x04 \x01(\t\x12\x10\n\x08peerhost\x18\x05 \x01(\t\x12\x10\n\x08sockport\x18\x06 \x01(\r\x12\x10\n\x08protocol\x18\x07 \x01(\t\x12\x12\n\nmountpoint\x18\x08 \x01(\t\x12\x14\n\x0cis_superuser\x18\t \x01(\x08\x12\x11\n\tanonymous\x18\n \x01(\x08\x12\n\n\x02\x63n\x18\x0b \x01(\t\x12\n\n\x02\x64n\x18\x0c \x01(\t\"\xd8\x01\n\x07Message\x12\x0c\n\x04node\x18\x01 \x01(\t\x12\n\n\x02id\x18\x02 \x01(\t\x12\x0b\n\x03qos\x18\x03 \x01(\r\x12\x0c\n\x04\x66rom\x18\x04 \x01(\t\x12\r\n\x05topic\x18\x05 \x01(\t\x12\x0f\n\x07payload\x18\x06 \x01(\x0c\x12\x11\n\ttimestamp\x18\x07 \x01(\x04\x12\x35\n\x07headers\x18\x08 \x03(\x0b\x32$.emqx.exhook.v2.Message.HeadersEntry\x1a.\n\x0cHeadersEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\'\n\x08Property\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t\"(\n\x0bTopicFilter\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0b\n\x03qos\x18\x02 \x01(\r\"J\n\x07SubOpts\x12\x0b\n\x03qos\x18\x01 \x01(\r\x12\r\n\x05share\x18\x02 \x01(\t\x12\n\n\x02rh\x18\x03 \x01(\r\x12\x0b\n\x03rap\x18\x04 \x01(\r\x12\n\n\x02nl\x18\x05 \x01(\r\"T\n\x0bRequestMeta\x12\x0c\n\x04node\x18\x01 \x01(\t\x12\x0f\n\x07version\x18\x02 \x01(\t\x12\x10\n\x08sysdescr\x18\x03 \x01(\t\x12\x14\n\x0c\x63luster_name\x18\x04 \x01(\t2\xc7\x0f\n\x0cHookProvider\x12[\n\x10OnProviderLoaded\x12%.emqx.exhook.v2.ProviderLoadedRequest\x1a\x1e.emqx.exhook.v2.LoadedResponse\"\x00\x12]\n\x12OnProviderUnloaded\x12\'.emqx.exhook.v2.ProviderUnloadedRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12W\n\x0fOnClientConnect\x12$.emqx.exhook.v2.ClientConnectRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12W\n\x0fOnClientConnack\x12$.emqx.exhook.v2.ClientConnackRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12[\n\x11OnClientConnected\x12&.emqx.exhook.v2.ClientConnectedRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12\x61\n\x14OnClientDisconnected\x12).emqx.exhook.v2.ClientDisconnectedRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12\x63\n\x14OnClientAuthenticate\x12).emqx.exhook.v2.ClientAuthenticateRequest\x1a\x1e.emqx.exhook.v2.ValuedResponse\"\x00\x12]\n\x11OnClientAuthorize\x12&.emqx.exhook.v2.ClientAuthorizeRequest\x1a\x1e.emqx.exhook.v2.ValuedResponse\"\x00\x12[\n\x11OnClientSubscribe\x12&.emqx.exhook.v2.ClientSubscribeRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12_\n\x13OnClientUnsubscribe\x12(.emqx.exhook.v2.ClientUnsubscribeRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12Y\n\x10OnSessionCreated\x12%.emqx.exhook.v2.SessionCreatedRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12_\n\x13OnSessionSubscribed\x12(.emqx.exhook.v2.SessionSubscribedRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12\x63\n\x15OnSessionUnsubscribed\x12*.emqx.exhook.v2.SessionUnsubscribedRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12Y\n\x10OnSessionResumed\x12%.emqx.exhook.v2.SessionResumedRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12]\n\x12OnSessionDiscarded\x12\'.emqx.exhook.v2.SessionDiscardedRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12]\n\x12OnSessionTakenover\x12\'.emqx.exhook.v2.SessionTakenoverRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12_\n\x13OnSessionTerminated\x12(.emqx.exhook.v2.SessionTerminatedRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12[\n\x10OnMessagePublish\x12%.emqx.exhook.v2.MessagePublishRequest\x1a\x1e.emqx.exhook.v2.ValuedResponse\"\x00\x12]\n\x12OnMessageDelivered\x12\'.emqx.exhook.v2.MessageDeliveredRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12Y\n\x10OnMessageDropped\x12%.emqx.exhook.v2.MessageDroppedRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x12U\n\x0eOnMessageAcked\x12#.emqx.exhook.v2.MessageAckedRequest\x1a\x1c.emqx.exhook.v2.EmptySuccess\"\x00\x42I\n\x0eio.emqx.exhookB\x0f\x45mqxExHookProtoP\x01Z\x13\x65mqx.io/grpc/exhook\xaa\x02\x0e\x45mqx.Exhook.V2b\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'exhook_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + DESCRIPTOR._serialized_options = b'\n\016io.emqx.exhookB\017EmqxExHookProtoP\001Z\023emqx.io/grpc/exhook\252\002\016Emqx.Exhook.V2' + _MESSAGE_HEADERSENTRY._options = None + _MESSAGE_HEADERSENTRY._serialized_options = b'8\001' + _globals['_PROVIDERLOADEDREQUEST']._serialized_start=32 + _globals['_PROVIDERLOADEDREQUEST']._serialized_end=142 + _globals['_PROVIDERUNLOADEDREQUEST']._serialized_start=144 + _globals['_PROVIDERUNLOADEDREQUEST']._serialized_end=212 + _globals['_CLIENTCONNECTREQUEST']._serialized_start=215 + _globals['_CLIENTCONNECTREQUEST']._serialized_end=365 + _globals['_CLIENTCONNACKREQUEST']._serialized_start=368 + _globals['_CLIENTCONNACKREQUEST']._serialized_end=539 + _globals['_CLIENTCONNECTEDREQUEST']._serialized_start=541 + _globals['_CLIENTCONNECTEDREQUEST']._serialized_end=656 + _globals['_CLIENTDISCONNECTEDREQUEST']._serialized_start=659 + _globals['_CLIENTDISCONNECTEDREQUEST']._serialized_end=793 + _globals['_CLIENTAUTHENTICATEREQUEST']._serialized_start=796 + _globals['_CLIENTAUTHENTICATEREQUEST']._serialized_end=930 + _globals['_CLIENTAUTHORIZEREQUEST']._serialized_start=933 + _globals['_CLIENTAUTHORIZEREQUEST']._serialized_end=1198 + _globals['_CLIENTAUTHORIZEREQUEST_AUTHORIZEREQTYPE']._serialized_start=1152 + _globals['_CLIENTAUTHORIZEREQUEST_AUTHORIZEREQTYPE']._serialized_end=1198 + _globals['_CLIENTSUBSCRIBEREQUEST']._serialized_start=1201 + _globals['_CLIENTSUBSCRIBEREQUEST']._serialized_end=1409 + _globals['_CLIENTUNSUBSCRIBEREQUEST']._serialized_start=1412 + _globals['_CLIENTUNSUBSCRIBEREQUEST']._serialized_end=1622 + _globals['_SESSIONCREATEDREQUEST']._serialized_start=1624 + _globals['_SESSIONCREATEDREQUEST']._serialized_end=1738 + _globals['_SESSIONSUBSCRIBEDREQUEST']._serialized_start=1741 + _globals['_SESSIONSUBSCRIBEDREQUEST']._serialized_end=1915 + _globals['_SESSIONUNSUBSCRIBEDREQUEST']._serialized_start=1918 + _globals['_SESSIONUNSUBSCRIBEDREQUEST']._serialized_end=2052 + _globals['_SESSIONRESUMEDREQUEST']._serialized_start=2054 + _globals['_SESSIONRESUMEDREQUEST']._serialized_end=2168 + _globals['_SESSIONDISCARDEDREQUEST']._serialized_start=2170 + _globals['_SESSIONDISCARDEDREQUEST']._serialized_end=2286 + _globals['_SESSIONTAKENOVERREQUEST']._serialized_start=2288 + _globals['_SESSIONTAKENOVERREQUEST']._serialized_end=2404 + _globals['_SESSIONTERMINATEDREQUEST']._serialized_start=2407 + _globals['_SESSIONTERMINATEDREQUEST']._serialized_end=2540 + _globals['_MESSAGEPUBLISHREQUEST']._serialized_start=2542 + _globals['_MESSAGEPUBLISHREQUEST']._serialized_end=2650 + _globals['_MESSAGEDELIVEREDREQUEST']._serialized_start=2653 + _globals['_MESSAGEDELIVEREDREQUEST']._serialized_end=2811 + _globals['_MESSAGEDROPPEDREQUEST']._serialized_start=2813 + _globals['_MESSAGEDROPPEDREQUEST']._serialized_end=2937 + _globals['_MESSAGEACKEDREQUEST']._serialized_start=2940 + _globals['_MESSAGEACKEDREQUEST']._serialized_end=3094 + _globals['_LOADEDRESPONSE']._serialized_start=3096 + _globals['_LOADEDRESPONSE']._serialized_end=3153 + _globals['_VALUEDRESPONSE']._serialized_start=3156 + _globals['_VALUEDRESPONSE']._serialized_end=3372 + _globals['_VALUEDRESPONSE_RESPONSEDTYPE']._serialized_start=3301 + _globals['_VALUEDRESPONSE_RESPONSEDTYPE']._serialized_end=3363 + _globals['_EMPTYSUCCESS']._serialized_start=3374 + _globals['_EMPTYSUCCESS']._serialized_end=3388 + _globals['_BROKERINFO']._serialized_start=3390 + _globals['_BROKERINFO']._serialized_end=3471 + _globals['_HOOKSPEC']._serialized_start=3473 + _globals['_HOOKSPEC']._serialized_end=3513 + _globals['_CONNINFO']._serialized_start=3516 + _globals['_CONNINFO']._serialized_end=3670 + _globals['_CLIENTINFO']._serialized_start=3673 + _globals['_CLIENTINFO']._serialized_end=3892 + _globals['_MESSAGE']._serialized_start=3895 + _globals['_MESSAGE']._serialized_end=4111 + _globals['_MESSAGE_HEADERSENTRY']._serialized_start=4065 + _globals['_MESSAGE_HEADERSENTRY']._serialized_end=4111 + _globals['_PROPERTY']._serialized_start=4113 + _globals['_PROPERTY']._serialized_end=4152 + _globals['_TOPICFILTER']._serialized_start=4154 + _globals['_TOPICFILTER']._serialized_end=4194 + _globals['_SUBOPTS']._serialized_start=4196 + _globals['_SUBOPTS']._serialized_end=4270 + _globals['_REQUESTMETA']._serialized_start=4272 + _globals['_REQUESTMETA']._serialized_end=4356 + _globals['_HOOKPROVIDER']._serialized_start=4359 + _globals['_HOOKPROVIDER']._serialized_end=6350 +# @@protoc_insertion_point(module_scope) diff --git a/exhook-svr-python/exhook_pb2_grpc.py b/exhook-svr-python/exhook_pb2_grpc.py new file mode 100644 index 0000000..aca507d --- /dev/null +++ b/exhook-svr-python/exhook_pb2_grpc.py @@ -0,0 +1,726 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + +import exhook_pb2 as exhook__pb2 + + +class HookProviderStub(object): + """Missing associated documentation comment in .proto file.""" + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.OnProviderLoaded = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnProviderLoaded', + request_serializer=exhook__pb2.ProviderLoadedRequest.SerializeToString, + response_deserializer=exhook__pb2.LoadedResponse.FromString, + ) + self.OnProviderUnloaded = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnProviderUnloaded', + request_serializer=exhook__pb2.ProviderUnloadedRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnClientConnect = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnClientConnect', + request_serializer=exhook__pb2.ClientConnectRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnClientConnack = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnClientConnack', + request_serializer=exhook__pb2.ClientConnackRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnClientConnected = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnClientConnected', + request_serializer=exhook__pb2.ClientConnectedRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnClientDisconnected = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnClientDisconnected', + request_serializer=exhook__pb2.ClientDisconnectedRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnClientAuthenticate = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnClientAuthenticate', + request_serializer=exhook__pb2.ClientAuthenticateRequest.SerializeToString, + response_deserializer=exhook__pb2.ValuedResponse.FromString, + ) + self.OnClientAuthorize = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnClientAuthorize', + request_serializer=exhook__pb2.ClientAuthorizeRequest.SerializeToString, + response_deserializer=exhook__pb2.ValuedResponse.FromString, + ) + self.OnClientSubscribe = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnClientSubscribe', + request_serializer=exhook__pb2.ClientSubscribeRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnClientUnsubscribe = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnClientUnsubscribe', + request_serializer=exhook__pb2.ClientUnsubscribeRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnSessionCreated = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnSessionCreated', + request_serializer=exhook__pb2.SessionCreatedRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnSessionSubscribed = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnSessionSubscribed', + request_serializer=exhook__pb2.SessionSubscribedRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnSessionUnsubscribed = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnSessionUnsubscribed', + request_serializer=exhook__pb2.SessionUnsubscribedRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnSessionResumed = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnSessionResumed', + request_serializer=exhook__pb2.SessionResumedRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnSessionDiscarded = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnSessionDiscarded', + request_serializer=exhook__pb2.SessionDiscardedRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnSessionTakenover = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnSessionTakenover', + request_serializer=exhook__pb2.SessionTakenoverRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnSessionTerminated = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnSessionTerminated', + request_serializer=exhook__pb2.SessionTerminatedRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnMessagePublish = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnMessagePublish', + request_serializer=exhook__pb2.MessagePublishRequest.SerializeToString, + response_deserializer=exhook__pb2.ValuedResponse.FromString, + ) + self.OnMessageDelivered = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnMessageDelivered', + request_serializer=exhook__pb2.MessageDeliveredRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnMessageDropped = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnMessageDropped', + request_serializer=exhook__pb2.MessageDroppedRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + self.OnMessageAcked = channel.unary_unary( + '/emqx.exhook.v2.HookProvider/OnMessageAcked', + request_serializer=exhook__pb2.MessageAckedRequest.SerializeToString, + response_deserializer=exhook__pb2.EmptySuccess.FromString, + ) + + +class HookProviderServicer(object): + """Missing associated documentation comment in .proto file.""" + + def OnProviderLoaded(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnProviderUnloaded(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnClientConnect(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnClientConnack(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnClientConnected(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnClientDisconnected(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnClientAuthenticate(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnClientAuthorize(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnClientSubscribe(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnClientUnsubscribe(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnSessionCreated(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnSessionSubscribed(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnSessionUnsubscribed(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnSessionResumed(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnSessionDiscarded(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnSessionTakenover(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnSessionTerminated(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnMessagePublish(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnMessageDelivered(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnMessageDropped(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def OnMessageAcked(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_HookProviderServicer_to_server(servicer, server): + rpc_method_handlers = { + 'OnProviderLoaded': grpc.unary_unary_rpc_method_handler( + servicer.OnProviderLoaded, + request_deserializer=exhook__pb2.ProviderLoadedRequest.FromString, + response_serializer=exhook__pb2.LoadedResponse.SerializeToString, + ), + 'OnProviderUnloaded': grpc.unary_unary_rpc_method_handler( + servicer.OnProviderUnloaded, + request_deserializer=exhook__pb2.ProviderUnloadedRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnClientConnect': grpc.unary_unary_rpc_method_handler( + servicer.OnClientConnect, + request_deserializer=exhook__pb2.ClientConnectRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnClientConnack': grpc.unary_unary_rpc_method_handler( + servicer.OnClientConnack, + request_deserializer=exhook__pb2.ClientConnackRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnClientConnected': grpc.unary_unary_rpc_method_handler( + servicer.OnClientConnected, + request_deserializer=exhook__pb2.ClientConnectedRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnClientDisconnected': grpc.unary_unary_rpc_method_handler( + servicer.OnClientDisconnected, + request_deserializer=exhook__pb2.ClientDisconnectedRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnClientAuthenticate': grpc.unary_unary_rpc_method_handler( + servicer.OnClientAuthenticate, + request_deserializer=exhook__pb2.ClientAuthenticateRequest.FromString, + response_serializer=exhook__pb2.ValuedResponse.SerializeToString, + ), + 'OnClientAuthorize': grpc.unary_unary_rpc_method_handler( + servicer.OnClientAuthorize, + request_deserializer=exhook__pb2.ClientAuthorizeRequest.FromString, + response_serializer=exhook__pb2.ValuedResponse.SerializeToString, + ), + 'OnClientSubscribe': grpc.unary_unary_rpc_method_handler( + servicer.OnClientSubscribe, + request_deserializer=exhook__pb2.ClientSubscribeRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnClientUnsubscribe': grpc.unary_unary_rpc_method_handler( + servicer.OnClientUnsubscribe, + request_deserializer=exhook__pb2.ClientUnsubscribeRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnSessionCreated': grpc.unary_unary_rpc_method_handler( + servicer.OnSessionCreated, + request_deserializer=exhook__pb2.SessionCreatedRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnSessionSubscribed': grpc.unary_unary_rpc_method_handler( + servicer.OnSessionSubscribed, + request_deserializer=exhook__pb2.SessionSubscribedRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnSessionUnsubscribed': grpc.unary_unary_rpc_method_handler( + servicer.OnSessionUnsubscribed, + request_deserializer=exhook__pb2.SessionUnsubscribedRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnSessionResumed': grpc.unary_unary_rpc_method_handler( + servicer.OnSessionResumed, + request_deserializer=exhook__pb2.SessionResumedRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnSessionDiscarded': grpc.unary_unary_rpc_method_handler( + servicer.OnSessionDiscarded, + request_deserializer=exhook__pb2.SessionDiscardedRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnSessionTakenover': grpc.unary_unary_rpc_method_handler( + servicer.OnSessionTakenover, + request_deserializer=exhook__pb2.SessionTakenoverRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnSessionTerminated': grpc.unary_unary_rpc_method_handler( + servicer.OnSessionTerminated, + request_deserializer=exhook__pb2.SessionTerminatedRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnMessagePublish': grpc.unary_unary_rpc_method_handler( + servicer.OnMessagePublish, + request_deserializer=exhook__pb2.MessagePublishRequest.FromString, + response_serializer=exhook__pb2.ValuedResponse.SerializeToString, + ), + 'OnMessageDelivered': grpc.unary_unary_rpc_method_handler( + servicer.OnMessageDelivered, + request_deserializer=exhook__pb2.MessageDeliveredRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnMessageDropped': grpc.unary_unary_rpc_method_handler( + servicer.OnMessageDropped, + request_deserializer=exhook__pb2.MessageDroppedRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + 'OnMessageAcked': grpc.unary_unary_rpc_method_handler( + servicer.OnMessageAcked, + request_deserializer=exhook__pb2.MessageAckedRequest.FromString, + response_serializer=exhook__pb2.EmptySuccess.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'emqx.exhook.v2.HookProvider', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + + + # This class is part of an EXPERIMENTAL API. +class HookProvider(object): + """Missing associated documentation comment in .proto file.""" + + @staticmethod + def OnProviderLoaded(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnProviderLoaded', + exhook__pb2.ProviderLoadedRequest.SerializeToString, + exhook__pb2.LoadedResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnProviderUnloaded(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnProviderUnloaded', + exhook__pb2.ProviderUnloadedRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnClientConnect(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnClientConnect', + exhook__pb2.ClientConnectRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnClientConnack(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnClientConnack', + exhook__pb2.ClientConnackRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnClientConnected(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnClientConnected', + exhook__pb2.ClientConnectedRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnClientDisconnected(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnClientDisconnected', + exhook__pb2.ClientDisconnectedRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnClientAuthenticate(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnClientAuthenticate', + exhook__pb2.ClientAuthenticateRequest.SerializeToString, + exhook__pb2.ValuedResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnClientAuthorize(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnClientAuthorize', + exhook__pb2.ClientAuthorizeRequest.SerializeToString, + exhook__pb2.ValuedResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnClientSubscribe(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnClientSubscribe', + exhook__pb2.ClientSubscribeRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnClientUnsubscribe(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnClientUnsubscribe', + exhook__pb2.ClientUnsubscribeRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnSessionCreated(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnSessionCreated', + exhook__pb2.SessionCreatedRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnSessionSubscribed(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnSessionSubscribed', + exhook__pb2.SessionSubscribedRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnSessionUnsubscribed(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnSessionUnsubscribed', + exhook__pb2.SessionUnsubscribedRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnSessionResumed(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnSessionResumed', + exhook__pb2.SessionResumedRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnSessionDiscarded(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnSessionDiscarded', + exhook__pb2.SessionDiscardedRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnSessionTakenover(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnSessionTakenover', + exhook__pb2.SessionTakenoverRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnSessionTerminated(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnSessionTerminated', + exhook__pb2.SessionTerminatedRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnMessagePublish(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnMessagePublish', + exhook__pb2.MessagePublishRequest.SerializeToString, + exhook__pb2.ValuedResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnMessageDelivered(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnMessageDelivered', + exhook__pb2.MessageDeliveredRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnMessageDropped(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnMessageDropped', + exhook__pb2.MessageDroppedRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def OnMessageAcked(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/emqx.exhook.v2.HookProvider/OnMessageAcked', + exhook__pb2.MessageAckedRequest.SerializeToString, + exhook__pb2.EmptySuccess.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/exhook-svr-python/exhook_server.py b/exhook-svr-python/exhook_server.py index f3c47cb..cb3b256 100644 --- a/exhook-svr-python/exhook_server.py +++ b/exhook-svr-python/exhook_server.py @@ -72,7 +72,11 @@ def OnClientDisconnected(self, request, context): def OnClientAuthenticate(self, request, context): print("OnClientAuthenticate:", request) - reply = exhook_pb2.ValuedResponse(type="STOP_AND_RETURN", bool_result=True) + clientinfo = request.clientinfo + if clientinfo.username == "baduser": + reply = exhook_pb2.ValuedResponse(type="STOP_AND_RETURN", bool_result=False) + else: + reply = exhook_pb2.ValuedResponse(type="STOP_AND_RETURN", bool_result=True) return reply def OnClientAuthorize(self, request, context): From f3818f5141d7877522cf2119c0e0e665f91e61bf Mon Sep 17 00:00:00 2001 From: JianBo He Date: Mon, 3 Jul 2023 11:12:35 +0800 Subject: [PATCH 2/2] chore: typos fixes --- exhook-svr-python/README.md | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/exhook-svr-python/README.md b/exhook-svr-python/README.md index ebbb593..4b0e593 100644 --- a/exhook-svr-python/README.md +++ b/exhook-svr-python/README.md @@ -6,7 +6,7 @@ This is a demo server written in python for exhook - [Python](https://www.python.org) 3.5 or higher - pip version 9.0.1 or higher -- EMQX 5.0 or above +- EMQX 5.0 or higher ### Install gRPC and gRPC tools @@ -20,14 +20,19 @@ python -m pip install grpcio-tools ## Test it with EMQX 1. Make sure that EMQX is version 5.0 or above. -2. Run the ExHook server by the following command: + +2. Start this ExHook Demo server by the following command: ``` python exhook_server.py ``` -3. Add an ExHook Server through the EMQX Dashboard and ensure that its address points to this example program. you can refer to the [Offcial Documentation](https://docs.emqx.com/en/enterprise/v5.1/extensions/exhook.html) -4. Observing this example program, it will print that it has received the `OnProviderLoaded` callback, indicating that they have successfully established a connection. +3. Configure ExHook by the EMQX Dashboard for this Demo server and ensure that its address points + to this example program. + For the detailed docs, refer to the + [Offcial Documentation](https://docs.emqx.com/en/enterprise/v5.1/extensions/exhook.html) +4. Observing this example program, it will print that it has received the `OnProviderLoaded` + callback, indicating that they have successfully established a connection. e.g: ``` OnProviderLoaded: broker { version: "5.1.0" @@ -49,16 +54,16 @@ OnClientConnected: ... OnClientConnack: ... ``` -At this point, the example program has successfully integrated with EMQX. +At this point, the example program has successfully integrated with EMQX and received all client +events from EMQX. ## Modify the exhook_server.py to deny all MQTT connecting request -In this section, we will take the `OnClientAuthenticate` callback as an example and -attempt to modify its implementation in `exhook_server.py` to deny some MQTT client -connections. +In this section, we will take the `OnClientAuthenticate` callback as an example and attempt to +modify its implementation in `exhook_server.py` to deny some MQTT client connections. -1. Modify the `OnClientAuthenticate` function in `exhook_server.py` to reject all - client logins with the username "baduser". +1. Modify the `OnClientAuthenticate` function in `exhook_server.py` to reject all client logins + with the username "baduser". The complete implementation of the modified function is as follows: ``` def OnClientAuthenticate(self, request, context): @@ -75,7 +80,8 @@ def OnClientAuthenticate(self, request, context): 3. Set the username of the MQTT client to "baduser" and connect to EMQX to test. -4. It can be observed that the client is unable to connect due to authentication failure, and the `exhook_server.py` will also output similar logs like this: +4. It can be observed that the client is unable to connect due to authentication failure, and the + `exhook_server.py` will also output similar logs like this: ``` OnClientConnect: ... OnClientAuthenticate: ... @@ -84,6 +90,9 @@ result_code: "not_authorized" ... ``` +Finally, a simple custom authentication based on ExHooK is completed. + + ## Update the exhook.proto to latest version Due to the inconsistency between the exhook.proto file used in this demo and the one included