コード例 #1
0
async def start_server(args):
    boxid = args.boxid

    ssl_context = get_ssl_context(args.ssl)

    # server etcd agent
    srv_names = list(srv_dict.keys())
    curr_box = get_box()
    curr_box.ssl_prefix = args.ssl
    await curr_box.start(boxid, srv_names)

    app = web.Application()
    app.router.add_post('/jsonrpc/2.0/api', handle)
    app.router.add_route('*', '/jsonrpc/2.0/ws', handle_ws)
    app.router.add_get('/metrics', handle_metrics)
    app.router.add_get('/metrics.json', handle_metrics_json)
    app.router.add_get('/', index)

    host, port = curr_box.bind.split(':')
    if not localbox_ip(host):
        host = '0.0.0.0'
    logger.warn('box {} launched as {}'.format(curr_box.boxid, curr_box.bind))
    handler = app.make_handler()
    loop = asyncio.get_event_loop()
    srv = await loop.create_server(handler, host, port, ssl=ssl_context)
    return srv, handler
コード例 #2
0
    async def run(self, args):
        # start cluster client and box
        httpd_mod = import_module(args.module)
        if hasattr(httpd_mod, 'Handler'):
            assert issubclass(httpd_mod.Handler, BaseHandler)
            mod_handler = httpd_mod.Handler()
        else:
            mod_handler = BaseHandler()
        parser = argparse.ArgumentParser(prog='bbox.py httpd')
        mod_handler.add_arguments(parser)
        sub_args = parser.parse_args(args.mod_args)

        if not args.boxid:
            args.boxid = uuid.uuid4().hex

        ssl_context = get_ssl_context(args.ssl)
        await get_cluster().start()

        http_app = await mod_handler.get_app(sub_args)
        _, handler = await bbox_server.start_server(args)

        http_handler = http_app.make_handler()

        host, port = args.bind.split(':')
        logger.warn('httpd starts at %s', args.bind)
        loop = asyncio.get_event_loop()
        await loop.create_server(http_handler, host, port, ssl=ssl_context)
        asyncio.ensure_future(self.wait_ttl(args.ttl))
        await mod_handler.start(sub_args)

        self.handler = handler
        self.mod_handler = mod_handler
        self.http_handler = http_handler
コード例 #3
0
    async def start_proxy_server(self, args:Namespace) -> None:
        boxid = args.boxid
        ssl_context = get_ssl_context(args.ssl)

        # server etcd agent
        curr_box = get_box()
        curr_box.ssl_prefix = args.ssl
        srv_names = args.srv_name
        await curr_box.start(boxid, srv_names)

        app = web.Application()
        app.router.add_post('/jsonrpc/2.0/api', self.proxy_requests)
        host, port = curr_box.bind.split(':')
        if not localbox_ip(host):
            host = '0.0.0.0'

        logger.warn('box {} launched as {}'.format(
            curr_box.boxid,
            curr_box.bind))
        handler = app.make_handler()
        loop = asyncio.get_event_loop()
        srv = await loop.create_server(
            handler,
            host, int(port),
            ssl=ssl_context)
コード例 #4
0
 def __init__(self, tunnel_url:str) -> None:
     self.parsed = urlparse(tunnel_url)
     if self.parsed.query:
         qs = parse_qs(self.parsed.query)
         certs = qs.get('ssl')
         if certs:
             self.ssl_context = get_ssl_context(certs[0])
     assert self.parsed.path and self.parsed.path.startswith('/')
     self.req_key = self.parsed.path[1:]
コード例 #5
0
ファイル: httpbase.py プロジェクト: danielsocials/bbox
    async def run(self, args):
        # start cluster client and box
        if not args.boxid:
            args.boxid = uuid.uuid4().hex

        ssl_context = get_ssl_context(args.ssl)
        await get_cluster().start()

        http_app = await self.get_app(args)
        _, handler = await bbox_server.start_server(args)

        http_handler = http_app.make_handler()

        host, port = args.bind.split(':')
        logger.warn('httpd starts at %s', args.bind)
        loop = asyncio.get_event_loop()
        await loop.create_server(http_handler, host, port, ssl=ssl_context)
        await self.start(args)
        self.handler = handler
        self.http_handler = http_handler