Beispiel #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()
    logging.info('Server stopped; exiting.')
Beispiel #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()

    if args.use_tls:
        private_key = resources.private_key()
        certificate_chain = resources.certificate_chain()
        server = implementations.server(
            methods.SERVICE_NAME,
            methods.SERVER_METHODS,
            args.port,
            private_key=private_key,
            certificate_chain=certificate_chain,
        )
    else:
        server = implementations.server(methods.SERVICE_NAME, methods.SERVER_METHODS, 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()
        logging.info("Server stopped; exiting.")
Beispiel #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',
                        dest='use_tls',
                        action='store_true')
    args = parser.parse_args()

    if args.use_tls:
        private_key = resources.private_key()
        certificate_chain = resources.certificate_chain()
        server = implementations.server(methods.SERVICE_NAME,
                                        methods.SERVER_METHODS,
                                        args.port,
                                        private_key=private_key,
                                        certificate_chain=certificate_chain)
    else:
        server = implementations.server(methods.SERVICE_NAME,
                                        methods.SERVER_METHODS, 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()
        logging.info('Server stopped; exiting.')
 def setUp(self):
   self.server = implementations.server(
       methods.SERVICE_NAME, methods.SERVER_METHODS, 0,
       private_key=resources.private_key(),
       certificate_chain=resources.certificate_chain())
   self.server.start()
   port = self.server.port()
   self.stub = implementations.stub(
       methods.SERVICE_NAME, methods.CLIENT_METHODS, 'localhost', port,
       secure=True, root_certificates=resources.test_root_certificates(),
       server_host_override=_SERVER_HOST_OVERRIDE)
Beispiel #5
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_client_credentials(
               resources.test_root_certificates(), None, None),
               _SERVER_HOST_OVERRIDE))
 def setUp(self):
     self.server = implementations.server(
         methods.SERVICE_NAME,
         methods.SERVER_METHODS,
         0,
         private_key=resources.private_key(),
         certificate_chain=resources.certificate_chain())
     self.server.start()
     port = self.server.port()
     self.stub = implementations.stub(
         methods.SERVICE_NAME,
         methods.CLIENT_METHODS,
         'localhost',
         port,
         secure=True,
         root_certificates=resources.test_root_certificates(),
         server_host_override=_SERVER_HOST_OVERRIDE)
Beispiel #7
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()
        logging.info("Server stopped; exiting.")