Пример #1
0
def get_server_credentials(use_tls):
    if use_tls:
        private_key = resources.private_key()
        certificate_chain = resources.certificate_chain()
        return grpc.ssl_server_credentials(
            ((private_key, certificate_chain), ))
    else:
        return grpc.alts_server_credentials()
Пример #2
0
def main():
    svr = grpc.server(futures.ThreadPoolExecutor())
    demo_pb2_grpc.add_GRPCDemoServicer_to_server(DemoServer(), svr)
    svr.add_secure_port(SERVER_ADDRESS,
                        server_credentials=grpc.alts_server_credentials())
    print("------------------start Python GRPC server with ALTS encryption")
    svr.start()
    svr.wait_for_termination()
Пример #3
0
 def _add_port(self):
     if self.alts:
         self.server.add_secure_port(self.endpoint,
                                     grpc.alts_server_credentials())
     elif self.private_key and self.certificate:
         self.server.add_secure_port(self.endpoint, self.server_credentials)
     elif self.private_key or self.certificate:
         # error
         raise ServerSSLConfigError(
             'If you want enable ssl feature, You Must set tls_key, certificate config both '
         )
     else:
         self.server.add_insecure_port(self.endpoint)
def main():
    os.environ['GRPC_VERBOSITY'] = 'debug'
    a = "unused variable."

    class CalculatorServicer(calculator_pb2_grpc.CalculatorServicer):
        def SquareRoot(self, request, context):
            response = calculator_pb2.Number()
            response.value = calculator.square_root(request.value)
            return response

        def Multiply(self, request, context):
            response = calculator_pb2.Number()
            response.value = calculator.multiply(request.val1, request.val2)
            return response

    #server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    server = grpc.server(futures.ThreadPoolExecutor())
    server_creds = grpc.alts_server_credentials()
    print(f'printing server credentials : {server_creds}')

    calculator_pb2_grpc.add_CalculatorServicer_to_server(
        CalculatorServicer(), server)

    print('Starting server. Listening on port 50051.')
    server.add_insecure_port('[::]:50051')
    #server.add_secure_port('localhost:50051', server_creds)
    server.start()

    b = False
    if b:
        print("hey this is a dead code block!!!")

    return 1
    try:
        while True:
            time.sleep(86400)
    except KeyboardInterrupt:
        server.stop(0)