diff --git a/Makefile b/Makefile index bd6d5ec..c743dbf 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ run: @poetry run python main.py lint: - @buf lint + @poetry run buf lint gen: - @buf generate + @poetry run buf generate diff --git a/main.py b/main.py index 765bcd3..ffaf25c 100644 --- a/main.py +++ b/main.py @@ -1,180 +1,37 @@ -import sys import asyncio -import typing -from plugin.v1.plugin_grpc import GatewayDPluginServiceBase -from google.protobuf.struct_pb2 import ListValue, Struct, Value -from google.protobuf.json_format import MessageToDict -import grpclib -from grpclib.server import Server, Stream -from grpclib.reflection.service import ServerReflection -from grpclib.health.service import Health -from grpclib.health.check import ServiceStatus -import logging - -logging.basicConfig(filename="plugin.log", level=logging.INFO) - - -async def defaults(stream: Stream[Struct, Struct]) -> None: - """Default handler for all hooks. - - Note: - The GatewayDPluginServiceBase class implements all hooks as abstract - methods, so we need to implement them all. This is a default handler - to use for all hooks that we don't need to implement. - """ - req = await stream.recv_message() - if req: - await stream.send_message(req) - else: - await stream.send_message(Struct()) - - -class Plugin(GatewayDPluginServiceBase): - async def GetPluginConfig(self, stream: Stream[Struct, Struct]) -> None: - # Ignore the request, as it is empty. - await stream.recv_message() - await stream.send_message( - Struct( - fields={ - "id": Value( - struct_value=Struct( - fields={ - "name": Value(string_value="plugin-template-python"), - "version": Value(string_value="0.1.0"), - "remoteUrl": Value( - string_value="github.com/gatewayd-io/plugin-template-python" - ), - } - ) - ), - "hooks": Value( - list_value=ListValue( - values=[ - # The list of hooks that the plugin implements. - Value(number_value=16), # OnTrafficFromClient - ] - ) - ), - } - ) - ) - - async def OnBooted(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnBooting(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnClosed(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnClosing(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnConfigLoaded(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnHook(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnNewClient(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnNewLogger(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnNewPool(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnNewProxy(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnNewServer(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnOpened(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnOpening(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnRun(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnShutdown(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnSignal(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnTick(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnTraffic(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnTrafficFromClient(self, stream: Stream[Struct, Struct]) -> None: - """ - This is an example of how to use the OnTrafficFromClient hook to - intercept traffic from the client and modify it before it is sent to - the server. In this example, we simply log the request and send it - to the server. - """ - req = await stream.recv_message() - if req: - logging.info(MessageToDict(req)) - await stream.send_message(req) - else: - await stream.send_message(Struct()) - - async def OnTrafficFromServer(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnTrafficToClient(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - async def OnTrafficToServer(self, stream: Stream[Struct, Struct]) -> None: - await defaults(stream) - - def __mapping__(self) -> typing.Dict[str, grpclib.const.Handler]: - """Mapping of service methods to handlers. - - Note: - This method is used to remap the service name to the plugin name, - so that the plugin health check works properly. - """ - # Get the mapping from the base class - mapping = super().__mapping__() - remapping = {} - - # Replace the service name with the plugin name - for path in mapping: - repath = path.replace("plugin.v1.GatewayDPluginService", "plugin") - remapping[repath] = mapping[path] +import sys - # Merge the two mappings - remapping.update(mapping) +import structlog +from grpclib.health.check import ServiceStatus +from grpclib.health.service import Health +from grpclib.reflection.service import ServerReflection +from grpclib.server import Server +from module import Plugin +from stdio_service import GRPCStdioService - return remapping +logger = structlog.get_logger() async def serve() -> None: # Instantiate the plugin. plugin = Plugin() + # Instantiate the stdio service. + stdio = GRPCStdioService() + # Create a health check for the plugin. plugin_health = ServiceStatus() plugin_health.set(True) health = Health({plugin: [plugin_health]}) # Add reflection for the plugin and health check. - services = ServerReflection.extend([plugin, health]) + services = ServerReflection.extend([plugin, stdio, health]) # Instantiate the server. server = Server(services) # Start the server. - await server.start("127.0.0.1", 12345) + await server.start("127.0.0.1", 50001) await server.wait_closed() @@ -183,7 +40,7 @@ async def serve() -> None: asyncio.set_event_loop(loop) try: # This is a special message that tells gatewayd to start the plugin. - print("1|0|tcp|127.0.0.1:12345|grpc") + print("1|0|tcp|127.0.0.1:50001|grpc") sys.stdout.flush() asyncio.run(serve()) except KeyboardInterrupt: diff --git a/mapping.py b/mapping.py new file mode 100644 index 0000000..9cf7624 --- /dev/null +++ b/mapping.py @@ -0,0 +1,25 @@ +import typing +import grpclib + + +class MappingMixin: + def __mapping__(self) -> typing.Dict[str, grpclib.const.Handler]: + """Mapping of service methods to handlers. + + Note: + This method is used to remap the service name to the plugin name, + so that the plugin health check works properly. + """ + # Get the mapping from the base class + mapping = super().__mapping__() # type: ignore + remapping = {} + + # Replace the service name with the plugin name + for path in mapping: + repath = path.replace("plugin.v1.GatewayDPluginService", "plugin") + remapping[repath] = mapping[path] + + # Merge the two mappings + remapping.update(mapping) + + return remapping diff --git a/module.py b/module.py new file mode 100644 index 0000000..008ef42 --- /dev/null +++ b/module.py @@ -0,0 +1,132 @@ +import structlog +from google.protobuf.json_format import MessageToDict +from google.protobuf.struct_pb2 import ListValue, Struct, Value +from grpclib.server import Stream + +from plugin.v1.plugin_grpc import GatewayDPluginServiceBase +from mapping import MappingMixin + +logger = structlog.get_logger() + + +async def defaults(stream: Stream[Struct, Struct]) -> None: + """Default handler for all hooks. + + Note: + The GatewayDPluginServiceBase class implements all hooks as abstract + methods, so we need to implement them all. This is a default handler + to use for all hooks that we don't need to implement. + """ + req = await stream.recv_message() + if req: + await stream.send_message(req) + else: + await stream.send_message(Struct()) + + +class Plugin(MappingMixin, GatewayDPluginServiceBase): + async def GetPluginConfig(self, stream: Stream[Struct, Struct]) -> None: + # Ignore the request, as it is empty. + await stream.recv_message() + await stream.send_message( + Struct( + fields={ + "id": Value( + struct_value=Struct( + fields={ + "name": Value(string_value="plugin-template-python"), + "version": Value(string_value="0.1.0"), + "remoteUrl": Value( + string_value="github.com/gatewayd-io/plugin-template-python" + ), + } + ) + ), + "hooks": Value( + list_value=ListValue( + values=[ + # The list of hooks that the plugin implements. + Value(number_value=16), # OnTrafficFromClient + ] + ) + ), + } + ) + ) + + async def OnBooted(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnBooting(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnClosed(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnClosing(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnConfigLoaded(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnHook(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnNewClient(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnNewLogger(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnNewPool(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnNewProxy(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnNewServer(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnOpened(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnOpening(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnRun(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnShutdown(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnSignal(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnTick(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnTraffic(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnTrafficFromClient(self, stream: Stream[Struct, Struct]) -> None: + """ + This is an example of how to use the OnTrafficFromClient hook to + intercept traffic from the client and modify it before it is sent to + the server. In this example, we simply log the request and send it + to the server. + """ + req = await stream.recv_message() + if req: + logger.info(MessageToDict(req)) + await stream.send_message(req) + else: + await stream.send_message(Struct()) + + async def OnTrafficFromServer(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnTrafficToClient(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) + + async def OnTrafficToServer(self, stream: Stream[Struct, Struct]) -> None: + await defaults(stream) diff --git a/plugin/v1/grpc_stdio.proto b/plugin/v1/grpc_stdio.proto new file mode 100644 index 0000000..08e4450 --- /dev/null +++ b/plugin/v1/grpc_stdio.proto @@ -0,0 +1,32 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +syntax = "proto3"; +package plugin.v1; + +import "google/protobuf/empty.proto"; + +// GRPCStdio is a service that is automatically run by the plugin process +// to stream any stdout/err data so that it can be mirrored on the plugin +// host side. +service GRPCStdio { + // StreamStdio returns a stream that contains all the stdout/stderr. + // This RPC endpoint must only be called ONCE. Once stdio data is consumed + // it is not sent again. + // + // Callers should connect early to prevent blocking on the plugin process. + rpc StreamStdio(google.protobuf.Empty) returns (stream StdioData); +} + +// StdioData is a single chunk of stdout or stderr data that is streamed +// from GRPCStdio. +message StdioData { + enum Channel { + INVALID = 0; + STDOUT = 1; + STDERR = 2; + } + + Channel channel = 1; + bytes data = 2; +} diff --git a/plugin/v1/grpc_stdio_grpc.py b/plugin/v1/grpc_stdio_grpc.py new file mode 100644 index 0000000..ebd2436 --- /dev/null +++ b/plugin/v1/grpc_stdio_grpc.py @@ -0,0 +1,41 @@ +# Generated by the Protocol Buffers compiler. DO NOT EDIT! +# source: plugin/v1/grpc_stdio.proto +# plugin: grpclib.plugin.main +import abc +import typing + +import grpclib.const +import grpclib.client +if typing.TYPE_CHECKING: + import grpclib.server + +import google.protobuf.empty_pb2 +import plugin.v1.grpc_stdio_pb2 + + +class GRPCStdioBase(abc.ABC): + + @abc.abstractmethod + async def StreamStdio(self, stream: 'grpclib.server.Stream[google.protobuf.empty_pb2.Empty, plugin.v1.grpc_stdio_pb2.StdioData]') -> None: + pass + + def __mapping__(self) -> typing.Dict[str, grpclib.const.Handler]: + return { + '/plugin.v1.GRPCStdio/StreamStdio': grpclib.const.Handler( + self.StreamStdio, + grpclib.const.Cardinality.UNARY_STREAM, + google.protobuf.empty_pb2.Empty, + plugin.v1.grpc_stdio_pb2.StdioData, + ), + } + + +class GRPCStdioStub: + + def __init__(self, channel: grpclib.client.Channel) -> None: + self.StreamStdio = grpclib.client.UnaryStreamMethod( + channel, + '/plugin.v1.GRPCStdio/StreamStdio', + google.protobuf.empty_pb2.Empty, + plugin.v1.grpc_stdio_pb2.StdioData, + ) diff --git a/plugin/v1/grpc_stdio_pb2.py b/plugin/v1/grpc_stdio_pb2.py new file mode 100644 index 0000000..1098420 --- /dev/null +++ b/plugin/v1/grpc_stdio_pb2.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: plugin/v1/grpc_stdio.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +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 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2 + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1aplugin/v1/grpc_stdio.proto\x12\tplugin.v1\x1a\x1bgoogle/protobuf/empty.proto\"\x87\x01\n\tStdioData\x12\x36\n\x07\x63hannel\x18\x01 \x01(\x0e\x32\x1c.plugin.v1.StdioData.ChannelR\x07\x63hannel\x12\x12\n\x04\x64\x61ta\x18\x02 \x01(\x0cR\x04\x64\x61ta\".\n\x07\x43hannel\x12\x0b\n\x07INVALID\x10\x00\x12\n\n\x06STDOUT\x10\x01\x12\n\n\x06STDERR\x10\x02\x32J\n\tGRPCStdio\x12=\n\x0bStreamStdio\x12\x16.google.protobuf.Empty\x1a\x14.plugin.v1.StdioData0\x01\x62\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'plugin.v1.grpc_stdio_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + _STDIODATA._serialized_start=71 + _STDIODATA._serialized_end=206 + _STDIODATA_CHANNEL._serialized_start=160 + _STDIODATA_CHANNEL._serialized_end=206 + _GRPCSTDIO._serialized_start=208 + _GRPCSTDIO._serialized_end=282 +# @@protoc_insertion_point(module_scope) diff --git a/plugin/v1/plugin.proto b/plugin/v1/plugin.proto index d6b0bba..181a384 100644 --- a/plugin/v1/plugin.proto +++ b/plugin/v1/plugin.proto @@ -4,8 +4,6 @@ package plugin.v1; import "google/protobuf/struct.proto"; -option go_package = "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin/v1"; - service GatewayDPluginService { // GetPluginConfig returns the plugin config upon registration rpc GetPluginConfig (google.protobuf.Struct) returns (google.protobuf.Struct); diff --git a/plugin/v1/plugin_grpc.py b/plugin/v1/plugin_grpc.py index eaf1c4c..915f75b 100644 --- a/plugin/v1/plugin_grpc.py +++ b/plugin/v1/plugin_grpc.py @@ -6,7 +6,6 @@ import grpclib.const import grpclib.client - if typing.TYPE_CHECKING: import grpclib.server @@ -15,302 +14,234 @@ class GatewayDPluginServiceBase(abc.ABC): + @abc.abstractmethod - async def GetPluginConfig( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def GetPluginConfig(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnConfigLoaded( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnConfigLoaded(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnNewLogger( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnNewLogger(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnNewPool( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnNewPool(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnNewClient( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnNewClient(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnNewProxy( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnNewProxy(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnNewServer( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnNewServer(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnSignal( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnSignal(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnRun( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnRun(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnBooting( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnBooting(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnBooted( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnBooted(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnOpening( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnOpening(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnOpened( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnOpened(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnClosing( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnClosing(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnClosed( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnClosed(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnTraffic( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnTraffic(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnTrafficFromClient( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnTrafficFromClient(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnTrafficToServer( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnTrafficToServer(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnTrafficFromServer( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnTrafficFromServer(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnTrafficToClient( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnTrafficToClient(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnShutdown( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnShutdown(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnTick( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnTick(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass @abc.abstractmethod - async def OnHook( - self, - stream: "grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]", - ) -> None: + async def OnHook(self, stream: 'grpclib.server.Stream[google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct]') -> None: pass def __mapping__(self) -> typing.Dict[str, grpclib.const.Handler]: return { - "/plugin.v1.GatewayDPluginService/GetPluginConfig": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/GetPluginConfig': grpclib.const.Handler( self.GetPluginConfig, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnConfigLoaded": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnConfigLoaded': grpclib.const.Handler( self.OnConfigLoaded, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnNewLogger": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnNewLogger': grpclib.const.Handler( self.OnNewLogger, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnNewPool": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnNewPool': grpclib.const.Handler( self.OnNewPool, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnNewClient": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnNewClient': grpclib.const.Handler( self.OnNewClient, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnNewProxy": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnNewProxy': grpclib.const.Handler( self.OnNewProxy, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnNewServer": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnNewServer': grpclib.const.Handler( self.OnNewServer, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnSignal": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnSignal': grpclib.const.Handler( self.OnSignal, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnRun": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnRun': grpclib.const.Handler( self.OnRun, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnBooting": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnBooting': grpclib.const.Handler( self.OnBooting, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnBooted": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnBooted': grpclib.const.Handler( self.OnBooted, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnOpening": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnOpening': grpclib.const.Handler( self.OnOpening, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnOpened": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnOpened': grpclib.const.Handler( self.OnOpened, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnClosing": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnClosing': grpclib.const.Handler( self.OnClosing, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnClosed": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnClosed': grpclib.const.Handler( self.OnClosed, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnTraffic": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnTraffic': grpclib.const.Handler( self.OnTraffic, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnTrafficFromClient": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnTrafficFromClient': grpclib.const.Handler( self.OnTrafficFromClient, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnTrafficToServer": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnTrafficToServer': grpclib.const.Handler( self.OnTrafficToServer, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnTrafficFromServer": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnTrafficFromServer': grpclib.const.Handler( self.OnTrafficFromServer, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnTrafficToClient": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnTrafficToClient': grpclib.const.Handler( self.OnTrafficToClient, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnShutdown": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnShutdown': grpclib.const.Handler( self.OnShutdown, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnTick": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnTick': grpclib.const.Handler( self.OnTick, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ), - "/plugin.v1.GatewayDPluginService/OnHook": grpclib.const.Handler( + '/plugin.v1.GatewayDPluginService/OnHook': grpclib.const.Handler( self.OnHook, grpclib.const.Cardinality.UNARY_UNARY, google.protobuf.struct_pb2.Struct, @@ -320,142 +251,143 @@ def __mapping__(self) -> typing.Dict[str, grpclib.const.Handler]: class GatewayDPluginServiceStub: + def __init__(self, channel: grpclib.client.Channel) -> None: self.GetPluginConfig = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/GetPluginConfig", + '/plugin.v1.GatewayDPluginService/GetPluginConfig', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnConfigLoaded = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnConfigLoaded", + '/plugin.v1.GatewayDPluginService/OnConfigLoaded', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnNewLogger = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnNewLogger", + '/plugin.v1.GatewayDPluginService/OnNewLogger', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnNewPool = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnNewPool", + '/plugin.v1.GatewayDPluginService/OnNewPool', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnNewClient = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnNewClient", + '/plugin.v1.GatewayDPluginService/OnNewClient', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnNewProxy = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnNewProxy", + '/plugin.v1.GatewayDPluginService/OnNewProxy', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnNewServer = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnNewServer", + '/plugin.v1.GatewayDPluginService/OnNewServer', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnSignal = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnSignal", + '/plugin.v1.GatewayDPluginService/OnSignal', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnRun = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnRun", + '/plugin.v1.GatewayDPluginService/OnRun', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnBooting = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnBooting", + '/plugin.v1.GatewayDPluginService/OnBooting', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnBooted = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnBooted", + '/plugin.v1.GatewayDPluginService/OnBooted', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnOpening = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnOpening", + '/plugin.v1.GatewayDPluginService/OnOpening', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnOpened = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnOpened", + '/plugin.v1.GatewayDPluginService/OnOpened', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnClosing = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnClosing", + '/plugin.v1.GatewayDPluginService/OnClosing', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnClosed = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnClosed", + '/plugin.v1.GatewayDPluginService/OnClosed', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnTraffic = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnTraffic", + '/plugin.v1.GatewayDPluginService/OnTraffic', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnTrafficFromClient = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnTrafficFromClient", + '/plugin.v1.GatewayDPluginService/OnTrafficFromClient', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnTrafficToServer = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnTrafficToServer", + '/plugin.v1.GatewayDPluginService/OnTrafficToServer', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnTrafficFromServer = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnTrafficFromServer", + '/plugin.v1.GatewayDPluginService/OnTrafficFromServer', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnTrafficToClient = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnTrafficToClient", + '/plugin.v1.GatewayDPluginService/OnTrafficToClient', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnShutdown = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnShutdown", + '/plugin.v1.GatewayDPluginService/OnShutdown', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnTick = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnTick", + '/plugin.v1.GatewayDPluginService/OnTick', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) self.OnHook = grpclib.client.UnaryUnaryMethod( channel, - "/plugin.v1.GatewayDPluginService/OnHook", + '/plugin.v1.GatewayDPluginService/OnHook', google.protobuf.struct_pb2.Struct, google.protobuf.struct_pb2.Struct, ) diff --git a/plugin/v1/plugin_pb2.py b/plugin/v1/plugin_pb2.py index 8d83740..da73c2f 100644 --- a/plugin/v1/plugin_pb2.py +++ b/plugin/v1/plugin_pb2.py @@ -6,7 +6,6 @@ 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 - # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() @@ -15,31 +14,27 @@ from google.protobuf import struct_pb2 as google_dot_protobuf_dot_struct__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( - b'\n\x16plugin/v1/plugin.proto\x12\tplugin.v1\x1a\x1cgoogle/protobuf/struct.proto"s\n\x08PluginID\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12\x18\n\x07version\x18\x02 \x01(\tR\x07version\x12\x1d\n\nremote_url\x18\x03 \x01(\tR\tremoteUrl\x12\x1a\n\x08\x63hecksum\x18\x04 \x01(\tR\x08\x63hecksum"\x81\x04\n\x0cPluginConfig\x12#\n\x02id\x18\x01 \x01(\x0b\x32\x13.plugin.v1.PluginIDR\x02id\x12 \n\x0b\x64\x65scription\x18\x02 \x01(\tR\x0b\x64\x65scription\x12\x18\n\x07\x61uthors\x18\x03 \x03(\tR\x07\x61uthors\x12\x18\n\x07license\x18\x04 \x01(\tR\x07license\x12\x1f\n\x0bproject_url\x18\x05 \x01(\tR\nprojectUrl\x12;\n\x06\x63onfig\x18\x06 \x03(\x0b\x32#.plugin.v1.PluginConfig.ConfigEntryR\x06\x63onfig\x12)\n\x05hooks\x18\x07 \x03(\x0e\x32\x13.plugin.v1.HookNameR\x05hooks\x12\x41\n\x08requires\x18\x08 \x03(\x0b\x32%.plugin.v1.PluginConfig.RequiresEntryR\x08requires\x12\x12\n\x04tags\x18\t \x03(\tR\x04tags\x12\x1e\n\ncategories\x18\n \x03(\tR\ncategories\x1a\x39\n\x0b\x43onfigEntry\x12\x10\n\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n\x05value\x18\x02 \x01(\tR\x05value:\x02\x38\x01\x1a;\n\rRequiresEntry\x12\x10\n\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n\x05value\x18\x02 \x01(\tR\x05value:\x02\x38\x01*\x92\x05\n\x08HookName\x12\x19\n\x15HOOK_NAME_UNSPECIFIED\x10\x00\x12\x1e\n\x1aHOOK_NAME_ON_CONFIG_LOADED\x10\x01\x12\x1b\n\x17HOOK_NAME_ON_NEW_LOGGER\x10\x02\x12\x19\n\x15HOOK_NAME_ON_NEW_POOL\x10\x03\x12\x1b\n\x17HOOK_NAME_ON_NEW_CLIENT\x10\x04\x12\x1a\n\x16HOOK_NAME_ON_NEW_PROXY\x10\x05\x12\x1b\n\x17HOOK_NAME_ON_NEW_SERVER\x10\x06\x12\x17\n\x13HOOK_NAME_ON_SIGNAL\x10\x07\x12\x14\n\x10HOOK_NAME_ON_RUN\x10\x08\x12\x18\n\x14HOOK_NAME_ON_BOOTING\x10\t\x12\x17\n\x13HOOK_NAME_ON_BOOTED\x10\n\x12\x18\n\x14HOOK_NAME_ON_OPENING\x10\x0b\x12\x17\n\x13HOOK_NAME_ON_OPENED\x10\x0c\x12\x18\n\x14HOOK_NAME_ON_CLOSING\x10\r\x12\x17\n\x13HOOK_NAME_ON_CLOSED\x10\x0e\x12\x18\n\x14HOOK_NAME_ON_TRAFFIC\x10\x0f\x12$\n HOOK_NAME_ON_TRAFFIC_FROM_CLIENT\x10\x10\x12"\n\x1eHOOK_NAME_ON_TRAFFIC_TO_SERVER\x10\x11\x12$\n HOOK_NAME_ON_TRAFFIC_FROM_SERVER\x10\x12\x12"\n\x1eHOOK_NAME_ON_TRAFFIC_TO_CLIENT\x10\x13\x12\x19\n\x15HOOK_NAME_ON_SHUTDOWN\x10\x14\x12\x15\n\x11HOOK_NAME_ON_TICK\x10\x15\x12\x15\n\x11HOOK_NAME_ON_HOOK\x10\x16\x32\xe9\x0b\n\x15GatewayDPluginService\x12\x43\n\x0fGetPluginConfig\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12\x42\n\x0eOnConfigLoaded\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12?\n\x0bOnNewLogger\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12=\n\tOnNewPool\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12?\n\x0bOnNewClient\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12>\n\nOnNewProxy\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12?\n\x0bOnNewServer\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12<\n\x08OnSignal\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12\x39\n\x05OnRun\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12=\n\tOnBooting\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12<\n\x08OnBooted\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12=\n\tOnOpening\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12<\n\x08OnOpened\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12=\n\tOnClosing\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12<\n\x08OnClosed\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12=\n\tOnTraffic\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12G\n\x13OnTrafficFromClient\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12\x45\n\x11OnTrafficToServer\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12G\n\x13OnTrafficFromServer\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12\x45\n\x11OnTrafficToClient\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12>\n\nOnShutdown\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12:\n\x06OnTick\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12:\n\x06OnHook\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.StructB6Z4github.com/gatewayd-io/gatewayd-plugin-sdk/plugin/v1b\x06proto3' -) +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x16plugin/v1/plugin.proto\x12\tplugin.v1\x1a\x1cgoogle/protobuf/struct.proto\"s\n\x08PluginID\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12\x18\n\x07version\x18\x02 \x01(\tR\x07version\x12\x1d\n\nremote_url\x18\x03 \x01(\tR\tremoteUrl\x12\x1a\n\x08\x63hecksum\x18\x04 \x01(\tR\x08\x63hecksum\"\x81\x04\n\x0cPluginConfig\x12#\n\x02id\x18\x01 \x01(\x0b\x32\x13.plugin.v1.PluginIDR\x02id\x12 \n\x0b\x64\x65scription\x18\x02 \x01(\tR\x0b\x64\x65scription\x12\x18\n\x07\x61uthors\x18\x03 \x03(\tR\x07\x61uthors\x12\x18\n\x07license\x18\x04 \x01(\tR\x07license\x12\x1f\n\x0bproject_url\x18\x05 \x01(\tR\nprojectUrl\x12;\n\x06\x63onfig\x18\x06 \x03(\x0b\x32#.plugin.v1.PluginConfig.ConfigEntryR\x06\x63onfig\x12)\n\x05hooks\x18\x07 \x03(\x0e\x32\x13.plugin.v1.HookNameR\x05hooks\x12\x41\n\x08requires\x18\x08 \x03(\x0b\x32%.plugin.v1.PluginConfig.RequiresEntryR\x08requires\x12\x12\n\x04tags\x18\t \x03(\tR\x04tags\x12\x1e\n\ncategories\x18\n \x03(\tR\ncategories\x1a\x39\n\x0b\x43onfigEntry\x12\x10\n\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n\x05value\x18\x02 \x01(\tR\x05value:\x02\x38\x01\x1a;\n\rRequiresEntry\x12\x10\n\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n\x05value\x18\x02 \x01(\tR\x05value:\x02\x38\x01*\x92\x05\n\x08HookName\x12\x19\n\x15HOOK_NAME_UNSPECIFIED\x10\x00\x12\x1e\n\x1aHOOK_NAME_ON_CONFIG_LOADED\x10\x01\x12\x1b\n\x17HOOK_NAME_ON_NEW_LOGGER\x10\x02\x12\x19\n\x15HOOK_NAME_ON_NEW_POOL\x10\x03\x12\x1b\n\x17HOOK_NAME_ON_NEW_CLIENT\x10\x04\x12\x1a\n\x16HOOK_NAME_ON_NEW_PROXY\x10\x05\x12\x1b\n\x17HOOK_NAME_ON_NEW_SERVER\x10\x06\x12\x17\n\x13HOOK_NAME_ON_SIGNAL\x10\x07\x12\x14\n\x10HOOK_NAME_ON_RUN\x10\x08\x12\x18\n\x14HOOK_NAME_ON_BOOTING\x10\t\x12\x17\n\x13HOOK_NAME_ON_BOOTED\x10\n\x12\x18\n\x14HOOK_NAME_ON_OPENING\x10\x0b\x12\x17\n\x13HOOK_NAME_ON_OPENED\x10\x0c\x12\x18\n\x14HOOK_NAME_ON_CLOSING\x10\r\x12\x17\n\x13HOOK_NAME_ON_CLOSED\x10\x0e\x12\x18\n\x14HOOK_NAME_ON_TRAFFIC\x10\x0f\x12$\n HOOK_NAME_ON_TRAFFIC_FROM_CLIENT\x10\x10\x12\"\n\x1eHOOK_NAME_ON_TRAFFIC_TO_SERVER\x10\x11\x12$\n HOOK_NAME_ON_TRAFFIC_FROM_SERVER\x10\x12\x12\"\n\x1eHOOK_NAME_ON_TRAFFIC_TO_CLIENT\x10\x13\x12\x19\n\x15HOOK_NAME_ON_SHUTDOWN\x10\x14\x12\x15\n\x11HOOK_NAME_ON_TICK\x10\x15\x12\x15\n\x11HOOK_NAME_ON_HOOK\x10\x16\x32\xe9\x0b\n\x15GatewayDPluginService\x12\x43\n\x0fGetPluginConfig\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12\x42\n\x0eOnConfigLoaded\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12?\n\x0bOnNewLogger\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12=\n\tOnNewPool\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12?\n\x0bOnNewClient\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12>\n\nOnNewProxy\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12?\n\x0bOnNewServer\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12<\n\x08OnSignal\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12\x39\n\x05OnRun\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12=\n\tOnBooting\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12<\n\x08OnBooted\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12=\n\tOnOpening\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12<\n\x08OnOpened\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12=\n\tOnClosing\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12<\n\x08OnClosed\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12=\n\tOnTraffic\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12G\n\x13OnTrafficFromClient\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12\x45\n\x11OnTrafficToServer\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12G\n\x13OnTrafficFromServer\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12\x45\n\x11OnTrafficToClient\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12>\n\nOnShutdown\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12:\n\x06OnTick\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Struct\x12:\n\x06OnHook\x12\x17.google.protobuf.Struct\x1a\x17.google.protobuf.Structb\x06proto3') _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, "plugin.v1.plugin_pb2", globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'plugin.v1.plugin_pb2', globals()) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - DESCRIPTOR._serialized_options = ( - b"Z4github.com/gatewayd-io/gatewayd-plugin-sdk/plugin/v1" - ) - _PLUGINCONFIG_CONFIGENTRY._options = None - _PLUGINCONFIG_CONFIGENTRY._serialized_options = b"8\001" - _PLUGINCONFIG_REQUIRESENTRY._options = None - _PLUGINCONFIG_REQUIRESENTRY._serialized_options = b"8\001" - _HOOKNAME._serialized_start = 701 - _HOOKNAME._serialized_end = 1359 - _PLUGINID._serialized_start = 67 - _PLUGINID._serialized_end = 182 - _PLUGINCONFIG._serialized_start = 185 - _PLUGINCONFIG._serialized_end = 698 - _PLUGINCONFIG_CONFIGENTRY._serialized_start = 580 - _PLUGINCONFIG_CONFIGENTRY._serialized_end = 637 - _PLUGINCONFIG_REQUIRESENTRY._serialized_start = 639 - _PLUGINCONFIG_REQUIRESENTRY._serialized_end = 698 - _GATEWAYDPLUGINSERVICE._serialized_start = 1362 - _GATEWAYDPLUGINSERVICE._serialized_end = 2875 + + DESCRIPTOR._options = None + _PLUGINCONFIG_CONFIGENTRY._options = None + _PLUGINCONFIG_CONFIGENTRY._serialized_options = b'8\001' + _PLUGINCONFIG_REQUIRESENTRY._options = None + _PLUGINCONFIG_REQUIRESENTRY._serialized_options = b'8\001' + _HOOKNAME._serialized_start=701 + _HOOKNAME._serialized_end=1359 + _PLUGINID._serialized_start=67 + _PLUGINID._serialized_end=182 + _PLUGINCONFIG._serialized_start=185 + _PLUGINCONFIG._serialized_end=698 + _PLUGINCONFIG_CONFIGENTRY._serialized_start=580 + _PLUGINCONFIG_CONFIGENTRY._serialized_end=637 + _PLUGINCONFIG_REQUIRESENTRY._serialized_start=639 + _PLUGINCONFIG_REQUIRESENTRY._serialized_end=698 + _GATEWAYDPLUGINSERVICE._serialized_start=1362 + _GATEWAYDPLUGINSERVICE._serialized_end=2875 # @@protoc_insertion_point(module_scope) diff --git a/poetry.lock b/poetry.lock index 69f1aeb..8f23adf 100644 --- a/poetry.lock +++ b/poetry.lock @@ -92,6 +92,22 @@ files = [ {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] +[[package]] +name = "fancycompleter" +version = "0.9.1" +description = "colorful TAB completion for Python prompt" +category = "dev" +optional = false +python-versions = "*" +files = [ + {file = "fancycompleter-0.9.1-py3-none-any.whl", hash = "sha256:dd076bca7d9d524cc7f25ec8f35ef95388ffef9ef46def4d3d25e9b044ad7080"}, + {file = "fancycompleter-0.9.1.tar.gz", hash = "sha256:09e0feb8ae242abdfd7ef2ba55069a46f011814a80fe5476be48f51b00247272"}, +] + +[package.dependencies] +pyreadline = {version = "*", markers = "platform_system == \"Windows\""} +pyrepl = ">=0.8.2" + [[package]] name = "grpcio" version = "1.53.0" @@ -268,6 +284,24 @@ files = [ {file = "hyperframe-6.0.1.tar.gz", hash = "sha256:ae510046231dc8e9ecb1a6586f63d2347bf4c8905914aa84ba585ae85f28a914"}, ] +[[package]] +name = "isort" +version = "5.12.0" +description = "A Python utility / library to sort Python imports." +category = "dev" +optional = false +python-versions = ">=3.8.0" +files = [ + {file = "isort-5.12.0-py3-none-any.whl", hash = "sha256:f84c2818376e66cf843d497486ea8fed8700b340f308f076c6fb1229dff318b6"}, + {file = "isort-5.12.0.tar.gz", hash = "sha256:8bef7dde241278824a6d83f44a544709b065191b95b6e50894bdc722fcba0504"}, +] + +[package.extras] +colors = ["colorama (>=0.4.3)"] +pipfile-deprecated-finder = ["pip-shims (>=0.5.2)", "pipreqs", "requirementslib"] +plugins = ["setuptools"] +requirements-deprecated-finder = ["pip-api", "pipreqs"] + [[package]] name = "multidict" version = "6.0.4" @@ -388,6 +422,27 @@ files = [ {file = "pathspec-0.11.1.tar.gz", hash = "sha256:2798de800fa92780e33acca925945e9a19a133b715067cf165b8866c15a31687"}, ] +[[package]] +name = "pdbpp" +version = "0.10.3" +description = "pdb++, a drop-in replacement for pdb" +category = "dev" +optional = false +python-versions = "*" +files = [ + {file = "pdbpp-0.10.3-py2.py3-none-any.whl", hash = "sha256:79580568e33eb3d6f6b462b1187f53e10cd8e4538f7d31495c9181e2cf9665d1"}, + {file = "pdbpp-0.10.3.tar.gz", hash = "sha256:d9e43f4fda388eeb365f2887f4e7b66ac09dce9b6236b76f63616530e2f669f5"}, +] + +[package.dependencies] +fancycompleter = ">=0.8" +pygments = "*" +wmctrl = "*" + +[package.extras] +funcsigs = ["funcsigs"] +testing = ["funcsigs", "pytest"] + [[package]] name = "platformdirs" version = "3.2.0" @@ -439,6 +494,43 @@ files = [ {file = "pycodestyle-2.10.0.tar.gz", hash = "sha256:347187bdb476329d98f695c213d7295a846d1152ff4fe9bacb8a9590b8ee7053"}, ] +[[package]] +name = "pygments" +version = "2.14.0" +description = "Pygments is a syntax highlighting package written in Python." +category = "dev" +optional = false +python-versions = ">=3.6" +files = [ + {file = "Pygments-2.14.0-py3-none-any.whl", hash = "sha256:fa7bd7bd2771287c0de303af8bfdfc731f51bd2c6a47ab69d117138893b82717"}, + {file = "Pygments-2.14.0.tar.gz", hash = "sha256:b3ed06a9e8ac9a9aae5a6f5dbe78a8a58655d17b43b93c078f094ddc476ae297"}, +] + +[package.extras] +plugins = ["importlib-metadata"] + +[[package]] +name = "pyreadline" +version = "2.1" +description = "A python implmementation of GNU readline." +category = "dev" +optional = false +python-versions = "*" +files = [ + {file = "pyreadline-2.1.zip", hash = "sha256:4530592fc2e85b25b1a9f79664433da09237c1a270e4d78ea5aa3a2c7229e2d1"}, +] + +[[package]] +name = "pyrepl" +version = "0.9.0" +description = "A library for building flexible command line interfaces" +category = "dev" +optional = false +python-versions = "*" +files = [ + {file = "pyrepl-0.9.0.tar.gz", hash = "sha256:292570f34b5502e871bbb966d639474f2b57fbfcd3373c2d6a2f3d56e681a775"}, +] + [[package]] name = "setuptools" version = "67.6.1" @@ -456,6 +548,24 @@ docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "pygments-g testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8 (<5)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pip-run (>=8.8)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] +[[package]] +name = "structlog" +version = "23.1.0" +description = "Structured Logging for Python" +category = "main" +optional = false +python-versions = ">=3.7" +files = [ + {file = "structlog-23.1.0-py3-none-any.whl", hash = "sha256:79b9e68e48b54e373441e130fa447944e6f87a05b35de23138e475c05d0f7e0e"}, + {file = "structlog-23.1.0.tar.gz", hash = "sha256:270d681dd7d163c11ba500bc914b2472d2b50a8ef00faa999ded5ff83a2f906b"}, +] + +[package.extras] +dev = ["structlog[docs,tests,typing]"] +docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-mermaid", "twisted"] +tests = ["coverage[toml]", "freezegun (>=0.2.8)", "pretend", "pytest (>=6.0)", "pytest-asyncio (>=0.17)", "simplejson"] +typing = ["mypy", "rich", "twisted"] + [[package]] name = "tomli" version = "2.0.1" @@ -468,7 +578,18 @@ files = [ {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] +[[package]] +name = "wmctrl" +version = "0.4" +description = "A tool to programmatically control windows inside X" +category = "dev" +optional = false +python-versions = "*" +files = [ + {file = "wmctrl-0.4.tar.gz", hash = "sha256:66cbff72b0ca06a22ec3883ac3a4d7c41078bdae4fb7310f52951769b10e14e0"}, +] + [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "7694a6b3519bc5db90b5d57491f184958eaf2bf772fe83663d56ad601ffa9561" +content-hash = "a6f06de3aff9daef425e6b726cd80fdface6607eac230bb1e380a1027da5b283" diff --git a/pyproject.toml b/pyproject.toml index 88113d4..53d8105 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ python = "^3.10" grpcio = "^1.53.0" black = "^23.3.0" grpclib = "^0.4.3" +structlog = "^23.1.0" [tool.poetry.group.dev.dependencies] @@ -20,6 +21,8 @@ grpclib = "^0.4.3" protobuf = "^4.22.1" pycodestyle = "^2.10.0" autopep8 = "^2.0.2" +isort = "^5.12.0" +pdbpp = "^0.10.3" [build-system] requires = ["poetry-core"] diff --git a/stdio_service.py b/stdio_service.py new file mode 100644 index 0000000..32d5660 --- /dev/null +++ b/stdio_service.py @@ -0,0 +1,17 @@ +from typing import Type +from plugin.v1.grpc_stdio_grpc import GRPCStdioBase +from grpclib.server import Stream +from plugin.v1.grpc_stdio_pb2 import DESCRIPTOR +from google.protobuf.empty_pb2 import Empty + +StdioData = DESCRIPTOR.message_types_by_name["StdioData"]._concrete_class +StdioDataType = Type[StdioData] + + +class GRPCStdioService(GRPCStdioBase): + async def StreamStdio(self, stream: Stream[Empty, StdioDataType]) -> None: + # Send the request back + await stream.send_message(StdioData( + channel=1, + data=b"Hello World", + )) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy