Example #1
0
 def setUp(self):
     self.server = test_pb2.beta_create_TestService_server(
         methods.TestService())
     port = self.server.add_insecure_port('[::]:0')
     self.server.start()
     self.stub = test_pb2.beta_create_TestService_stub(
         implementations.insecure_channel('localhost', port))
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 = 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.')
Example #3
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.')
 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(
           'localhost', 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))
 def setUp(self):
   self.server = test_pb2.beta_create_TestService_server(methods.TestService())
   port = self.server.add_insecure_port('[::]:0')
   self.server.start()
   self.stub = test_pb2.beta_create_TestService_stub(
       implementations.insecure_channel('[::]', port))