Example #1
0
def serve():
    parser = argparse.ArgumentParser()
    parser.add_argument('--port', help='the port on which to serve', type=int)
    parser.add_argument('--use_tls',
                        help='require a secure connection',
                        default=False,
                        type=resources.parse_bool)
    args = parser.parse_args()

    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    test_pb2.add_TestServiceServicer_to_server(methods.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()
    logging.info('Server serving.')
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except BaseException as e:
        logging.info('Caught exception "%s"; stopping server...', e)
        server.stop(None)
        logging.info('Server stopped; exiting.')
Example #2
0
def serve():
    parser = argparse.ArgumentParser()
    parser.add_argument("--port", help="the port on which to serve", type=int)
    parser.add_argument("--use_tls", help="require a secure connection", default=False, type=resources.parse_bool)
    args = parser.parse_args()

    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    test_pb2.add_TestServiceServicer_to_server(methods.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()
    logging.info("Server serving.")
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except BaseException as e:
        logging.info('Caught exception "%s"; stopping server...', e)
        server.stop(None)
        logging.info("Server stopped; exiting.")
Example #3
0
 def setUp(self):
     self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
     test_pb2.add_TestServiceServicer_to_server(methods.TestService(),
                                                self.server)
     port = self.server.add_insecure_port('[::]:0')
     self.server.start()
     self.stub = test_pb2.TestServiceStub(
         grpc.insecure_channel('localhost:{}'.format(port)))
Example #4
0
 def setUp(self):
   self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
   test_pb2.add_TestServiceServicer_to_server(
       methods.TestService(), self.server)
   port = self.server.add_insecure_port('[::]:0')
   self.server.start()
   self.stub = test_pb2.TestServiceStub(
       grpc.insecure_channel('localhost:{}'.format(port)))
Example #5
0
 def setUp(self):
   self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
   test_pb2.add_TestServiceServicer_to_server(
       methods.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.TestServiceStub(
       grpc.secure_channel(
           'localhost:{}'.format(port),
           grpc.ssl_channel_credentials(resources.test_root_certificates()),
           (('grpc.ssl_target_name_override', _SERVER_HOST_OVERRIDE,),)))
Example #6
0
 def setUp(self):
     self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
     test_pb2.add_TestServiceServicer_to_server(methods.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.TestServiceStub(
         grpc.secure_channel(
             'localhost:{}'.format(port),
             grpc.ssl_channel_credentials(
                 resources.test_root_certificates()), ((
                     'grpc.ssl_target_name_override',
                     _SERVER_HOST_OVERRIDE,
                 ), )))