|
|
|
@ -17,15 +17,17 @@ import grpc |
|
|
|
|
from google.protobuf import descriptor_pb2 |
|
|
|
|
from google.protobuf import descriptor_pool |
|
|
|
|
|
|
|
|
|
from grpc_reflection.v1alpha import reflection_pb2 |
|
|
|
|
from grpc_reflection.v1alpha import reflection_pb2_grpc |
|
|
|
|
from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 |
|
|
|
|
from grpc_reflection.v1alpha import reflection_pb2_grpc as _reflection_pb2_grpc |
|
|
|
|
|
|
|
|
|
_POOL = descriptor_pool.Default() |
|
|
|
|
SERVICE_NAME = _reflection_pb2.DESCRIPTOR.services_by_name[ |
|
|
|
|
'ServerReflection'].full_name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _not_found_error(): |
|
|
|
|
return reflection_pb2.ServerReflectionResponse( |
|
|
|
|
error_response=reflection_pb2.ErrorResponse( |
|
|
|
|
return _reflection_pb2.ServerReflectionResponse( |
|
|
|
|
error_response=_reflection_pb2.ErrorResponse( |
|
|
|
|
error_code=grpc.StatusCode.NOT_FOUND.value[0], |
|
|
|
|
error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(), |
|
|
|
|
)) |
|
|
|
@ -35,12 +37,12 @@ def _file_descriptor_response(descriptor): |
|
|
|
|
proto = descriptor_pb2.FileDescriptorProto() |
|
|
|
|
descriptor.CopyToProto(proto) |
|
|
|
|
serialized_proto = proto.SerializeToString() |
|
|
|
|
return reflection_pb2.ServerReflectionResponse( |
|
|
|
|
file_descriptor_response=reflection_pb2.FileDescriptorResponse( |
|
|
|
|
return _reflection_pb2.ServerReflectionResponse( |
|
|
|
|
file_descriptor_response=_reflection_pb2.FileDescriptorResponse( |
|
|
|
|
file_descriptor_proto=(serialized_proto,)),) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReflectionServicer(reflection_pb2_grpc.ServerReflectionServicer): |
|
|
|
|
class ReflectionServicer(_reflection_pb2_grpc.ServerReflectionServicer): |
|
|
|
|
"""Servicer handling RPCs for service statuses.""" |
|
|
|
|
|
|
|
|
|
def __init__(self, service_names, pool=None): |
|
|
|
@ -94,17 +96,17 @@ class ReflectionServicer(reflection_pb2_grpc.ServerReflectionServicer): |
|
|
|
|
except KeyError: |
|
|
|
|
return _not_found_error() |
|
|
|
|
else: |
|
|
|
|
return reflection_pb2.ServerReflectionResponse( |
|
|
|
|
all_extension_numbers_response=reflection_pb2. |
|
|
|
|
return _reflection_pb2.ServerReflectionResponse( |
|
|
|
|
all_extension_numbers_response=_reflection_pb2. |
|
|
|
|
ExtensionNumberResponse( |
|
|
|
|
base_type_name=message_descriptor.full_name, |
|
|
|
|
extension_number=extension_numbers)) |
|
|
|
|
|
|
|
|
|
def _list_services(self): |
|
|
|
|
return reflection_pb2.ServerReflectionResponse( |
|
|
|
|
list_services_response=reflection_pb2.ListServiceResponse( |
|
|
|
|
return _reflection_pb2.ServerReflectionResponse( |
|
|
|
|
list_services_response=_reflection_pb2.ListServiceResponse( |
|
|
|
|
service=[ |
|
|
|
|
reflection_pb2.ServiceResponse(name=service_name) |
|
|
|
|
_reflection_pb2.ServiceResponse(name=service_name) |
|
|
|
|
for service_name in self._service_names |
|
|
|
|
])) |
|
|
|
|
|
|
|
|
@ -126,8 +128,8 @@ class ReflectionServicer(reflection_pb2_grpc.ServerReflectionServicer): |
|
|
|
|
elif request.HasField('list_services'): |
|
|
|
|
yield self._list_services() |
|
|
|
|
else: |
|
|
|
|
yield reflection_pb2.ServerReflectionResponse( |
|
|
|
|
error_response=reflection_pb2.ErrorResponse( |
|
|
|
|
yield _reflection_pb2.ServerReflectionResponse( |
|
|
|
|
error_response=_reflection_pb2.ErrorResponse( |
|
|
|
|
error_code=grpc.StatusCode.INVALID_ARGUMENT.value[0], |
|
|
|
|
error_message=grpc.StatusCode.INVALID_ARGUMENT.value[1] |
|
|
|
|
.encode(), |
|
|
|
@ -142,5 +144,5 @@ def enable_server_reflection(service_names, server, pool=None): |
|
|
|
|
server: grpc.Server to which reflection service will be added. |
|
|
|
|
pool: DescriptorPool object to use (descriptor_pool.Default() if None). |
|
|
|
|
""" |
|
|
|
|
reflection_pb2_grpc.add_ServerReflectionServicer_to_server( |
|
|
|
|
_reflection_pb2_grpc.add_ServerReflectionServicer_to_server( |
|
|
|
|
ReflectionServicer(service_names, pool=pool), server) |
|
|
|
|