def serve(): parser = argparse.ArgumentParser() parser.add_argument('--port', type=int, required=True, help='the port on which to serve') parser.add_argument('--use_tls', default=False, type=resources.parse_bool, help='require a secure connection') args = parser.parse_args() server = test_common.test_server() test_pb2_grpc.add_TestServiceServicer_to_server(service.TestService(), server) if args.use_tls: private_key = resources.private_key() certificate_chain = resources.certificate_chain() credentials = grpc.ssl_server_credentials( ((private_key, certificate_chain), )) server.add_secure_port('[::]:{}'.format(args.port), credentials) else: server.add_insecure_port('[::]:{}'.format(args.port)) server.start() _LOGGER.info('Server serving.') server.wait_for_termination() _LOGGER.info('Server stopped; exiting.')
def setUp(self): self.server = test_common.test_server() test_pb2_grpc.add_TestServiceServicer_to_server( service.TestService(), self.server) port = self.server.add_insecure_port('[::]:0') self.server.start() self.stub = test_pb2_grpc.TestServiceStub( grpc.insecure_channel('localhost:{}'.format(port)))
def serve(): args = parse_interop_server_arguments() server = test_common.test_server() test_pb2_grpc.add_TestServiceServicer_to_server(service.TestService(), server) if args.use_tls: credentials = get_server_credentials() server.add_secure_port('[::]:{}'.format(args.port), credentials) else: server.add_insecure_port('[::]:{}'.format(args.port)) server.start() _LOGGER.info('Server serving.') server.wait_for_termination() _LOGGER.info('Server stopped; exiting.')
def setUp(self): self.server = test_common.test_server() test_pb2_grpc.add_TestServiceServicer_to_server( service.TestService(), self.server) port = self.server.add_secure_port( '[::]:0', grpc.ssl_server_credentials([(resources.private_key(), resources.certificate_chain())])) self.server.start() self.stub = test_pb2_grpc.TestServiceStub( grpc.secure_channel( 'localhost:{}'.format(port), grpc.ssl_channel_credentials( resources.test_root_certificates()), (( 'grpc.ssl_target_name_override', _SERVER_HOST_OVERRIDE, ), )))