diff --git a/Makefile b/Makefile index 173d03dda..42bfecddf 100644 --- a/Makefile +++ b/Makefile @@ -61,13 +61,11 @@ cleanup-generated-changelog: release: poetry run python scripts/release.py -download-protoc-compiler: - curl -0L https://github.com/protocolbuffers/protobuf/releases/download/v25.0/protoc-25.0-osx-aarch_64.zip --output protoc-25.0-osx-aarch_64.zip - generate-grpc: python -m grpc_tools.protoc \ -Irasa_sdk/grpc_py=./proto \ --python_out=. \ --grpc_python_out=. \ --pyi_out=. \ - proto/action_webhook.proto \ No newline at end of file + proto/action_webhook.proto \ + proto/health.proto \ No newline at end of file diff --git a/proto/health.proto b/proto/health.proto new file mode 100644 index 000000000..4f81c56d4 --- /dev/null +++ b/proto/health.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package grpc.health.v1; + +message HealthCheckRequest {} + +message HealthCheckResponse {} + +service Health { + rpc Check(HealthCheckRequest) returns (HealthCheckResponse); +} \ No newline at end of file diff --git a/rasa_sdk/grpc_py/health_pb2.py b/rasa_sdk/grpc_py/health_pb2.py new file mode 100644 index 000000000..36205e83c --- /dev/null +++ b/rasa_sdk/grpc_py/health_pb2.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: rasa_sdk/grpc_py/health.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\x1drasa_sdk/grpc_py/health.proto\x12\x0egrpc.health.v1\"\x14\n\x12HealthCheckRequest\"\x15\n\x13HealthCheckResponse2Z\n\x06Health\x12P\n\x05\x43heck\x12\".grpc.health.v1.HealthCheckRequest\x1a#.grpc.health.v1.HealthCheckResponseb\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'rasa_sdk.grpc_py.health_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + _globals['_HEALTHCHECKREQUEST']._serialized_start=49 + _globals['_HEALTHCHECKREQUEST']._serialized_end=69 + _globals['_HEALTHCHECKRESPONSE']._serialized_start=71 + _globals['_HEALTHCHECKRESPONSE']._serialized_end=92 + _globals['_HEALTH']._serialized_start=94 + _globals['_HEALTH']._serialized_end=184 +# @@protoc_insertion_point(module_scope) diff --git a/rasa_sdk/grpc_py/health_pb2.pyi b/rasa_sdk/grpc_py/health_pb2.pyi new file mode 100644 index 000000000..a58962527 --- /dev/null +++ b/rasa_sdk/grpc_py/health_pb2.pyi @@ -0,0 +1,13 @@ +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from typing import ClassVar as _ClassVar + +DESCRIPTOR: _descriptor.FileDescriptor + +class HealthCheckRequest(_message.Message): + __slots__ = [] + def __init__(self) -> None: ... + +class HealthCheckResponse(_message.Message): + __slots__ = [] + def __init__(self) -> None: ... diff --git a/rasa_sdk/grpc_py/health_pb2_grpc.py b/rasa_sdk/grpc_py/health_pb2_grpc.py new file mode 100644 index 000000000..f20a40588 --- /dev/null +++ b/rasa_sdk/grpc_py/health_pb2_grpc.py @@ -0,0 +1,66 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + +from rasa_sdk.grpc_py import health_pb2 as rasa__sdk_dot_grpc__py_dot_health__pb2 + + +class HealthStub(object): + """Missing associated documentation comment in .proto file.""" + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.Check = channel.unary_unary( + '/grpc.health.v1.Health/Check', + request_serializer=rasa__sdk_dot_grpc__py_dot_health__pb2.HealthCheckRequest.SerializeToString, + response_deserializer=rasa__sdk_dot_grpc__py_dot_health__pb2.HealthCheckResponse.FromString, + ) + + +class HealthServicer(object): + """Missing associated documentation comment in .proto file.""" + + def Check(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_HealthServicer_to_server(servicer, server): + rpc_method_handlers = { + 'Check': grpc.unary_unary_rpc_method_handler( + servicer.Check, + request_deserializer=rasa__sdk_dot_grpc__py_dot_health__pb2.HealthCheckRequest.FromString, + response_serializer=rasa__sdk_dot_grpc__py_dot_health__pb2.HealthCheckResponse.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'grpc.health.v1.Health', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + + + # This class is part of an EXPERIMENTAL API. +class Health(object): + """Missing associated documentation comment in .proto file.""" + + @staticmethod + def Check(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, '/grpc.health.v1.Health/Check', + rasa__sdk_dot_grpc__py_dot_health__pb2.HealthCheckRequest.SerializeToString, + rasa__sdk_dot_grpc__py_dot_health__pb2.HealthCheckResponse.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/rasa_sdk/grpc_server.py b/rasa_sdk/grpc_server.py index 136e12927..1b4f98d1e 100644 --- a/rasa_sdk/grpc_server.py +++ b/rasa_sdk/grpc_server.py @@ -3,6 +3,7 @@ import signal import asyncio +import ssl import grpc import logging @@ -171,12 +172,13 @@ async def run_grpc( ) if ssl_certificate and ssl_keyfile: # Use SSL/TLS if certificate and key are provided - # ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) - # ssl_context.load_cert_chain( - # ssl_certificate, - # keyfile=ssl_keyfile, - # password=ssl_password if ssl_password else None, - # ) + ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) + ssl_context.load_cert_chain( + ssl_certificate, + keyfile=ssl_keyfile, + password=ssl_password if ssl_password else None, + ) + grpc.ssl_channel_credentials() private_key = open(ssl_keyfile, "rb").read() certificate_chain = open(ssl_certificate, "rb").read() logger.info(f"Starting gRPC server with SSL support on port {port}")