Esempio n. 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', 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.secure_server(
        methods.SERVER_METHODS, args.port, private_key, certificate_chain)
  else:
    server = implementations.insecure_server(
        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.')
Esempio n. 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',
                        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.secure_server(methods.SERVER_METHODS,
                                               args.port, private_key,
                                               certificate_chain)
    else:
        server = implementations.insecure_server(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.')
Esempio n. 3
0
 def setUp(self):
   self.server = implementations.secure_server(
       methods.SERVER_METHODS, 0, resources.private_key(),
       resources.certificate_chain())
   self.server.start()
   port = self.server.port()
   self.stub = implementations.secure_stub(
       methods.CLIENT_METHODS, 'localhost', port,
       resources.test_root_certificates(), None, None,
       server_host_override=_SERVER_HOST_OVERRIDE)
Esempio n. 4
0
 def setUp(self):
     self.server = implementations.secure_server(
         methods.SERVICE_NAME, methods.SERVER_METHODS, 0,
         resources.private_key(), resources.certificate_chain())
     self.server.start()
     port = self.server.port()
     self.stub = implementations.secure_stub(
         methods.SERVICE_NAME,
         methods.CLIENT_METHODS,
         'localhost',
         port,
         resources.test_root_certificates(),
         None,
         None,
         server_host_override=_SERVER_HOST_OVERRIDE)