예제 #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 = test_pb2.beta_create_TestService_server(methods.TestService())
    if args.use_tls:
        private_key = resources.private_key()
        certificate_chain = resources.certificate_chain()
        credentials = implementations.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(0)
        logging.info('Server stopped; exiting.')
예제 #2
0
파일: server.py 프로젝트: Aj0Ay/grpc
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 = test_pb2.beta_create_TestService_server(methods.TestService())
  if args.use_tls:
    private_key = resources.private_key()
    certificate_chain = resources.certificate_chain()
    credentials = implementations.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(0)
    logging.info('Server stopped; exiting.')
예제 #3
0
파일: server.py 프로젝트: jacklicn/grpc
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.")
예제 #4
0
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(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()
    _LOGGER.info('Server serving.')
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except BaseException as e:
        _LOGGER.info('Caught exception "%s"; stopping server...', e)
        server.stop(None)
        _LOGGER.info('Server stopped; exiting.')
예제 #5
0
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.')
예제 #6
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()
예제 #7
0
 def setUp(self):
   self.server = test_pb2.beta_create_TestService_server(methods.TestService())
   port = self.server.add_secure_port(
       '[::]:0', implementations.ssl_server_credentials(
           [(resources.private_key(), resources.certificate_chain())]))
   self.server.start()
   self.stub = test_pb2.beta_create_TestService_stub(
       test_utilities.not_really_secure_channel(
           '[::]', port, implementations.ssl_channel_credentials(
               resources.test_root_certificates()),
               _SERVER_HOST_OVERRIDE))
 def setUp(self):
   self.server = test_pb2.beta_create_TestService_server(methods.TestService())
   port = self.server.add_secure_port(
       '[::]:0', implementations.ssl_server_credentials(
           [(resources.private_key(), resources.certificate_chain())]))
   self.server.start()
   self.stub = test_pb2.beta_create_TestService_stub(
       test_utilities.not_really_secure_channel(
           '[::]', port, implementations.ssl_channel_credentials(
               resources.test_root_certificates()),
               _SERVER_HOST_OVERRIDE))
예제 #9
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,),)))
예제 #10
0
 def setUp(self):
     self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
     test_pb2_grpc.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_grpc.TestServiceStub(
         grpc.secure_channel('localhost:{}'.format(port),
                             grpc.ssl_channel_credentials(
                                 resources.test_root_certificates()), (
                                     ('grpc.ssl_target_name_override',
                                      _SERVER_HOST_OVERRIDE,),)))
예제 #11
0
    async def setUp(self):
        server_credentials = grpc.ssl_server_credentials([
            (resources.private_key(), resources.certificate_chain())
        ])
        channel_credentials = grpc.ssl_channel_credentials(
            resources.test_root_certificates())
        channel_options = ((
            'grpc.ssl_target_name_override',
            _SERVER_HOST_OVERRIDE,
        ), )

        address, self._server = await start_test_server(
            secure=True, server_credentials=server_credentials)
        self._channel = aio.secure_channel(address, channel_credentials,
                                           channel_options)
        self._stub = test_pb2_grpc.TestServiceStub(self._channel)
예제 #12
0
 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,
                                 ),)))
예제 #13
0
def get_server_credentials():
    private_key = resources.private_key()
    certificate_chain = resources.certificate_chain()
    return grpc.ssl_server_credentials(((private_key, certificate_chain), ))