Exemplo n.º 1
0
def main():

    config = load_config(extra_args_funcs=(gw_args, Logger.update_log_args))
    logger = Logger(config)
    logger.add_pkg('aiotools')
    logger.add_pkg('aiopg')
    logger.add_pkg('ai.backend')

    with logger:
        log.info(f'Backend.AI Gateway {__version__}')
        log.info(f'runtime: {env_info()}')
        log_config = logging.getLogger('ai.backend.gateway.config')
        log_config.debug('debug mode enabled.')
        if config.debug:
            aiohttp.log.server_logger.setLevel('DEBUG')
            aiohttp.log.access_logger.setLevel('DEBUG')
        else:
            aiohttp.log.server_logger.setLevel('WARNING')
            aiohttp.log.access_logger.setLevel('WARNING')

        asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
        try:
            aiotools.start_server(server_main,
                                  num_workers=config.num_proc,
                                  extra_procs=[event_router],
                                  args=(config, ))
        finally:
            log.info('terminated.')
Exemplo n.º 2
0
    ak = 'AKIA' + base64.b32encode(secrets.token_bytes(10)).decode('ascii')
    sk = secrets.token_urlsafe(30)
    return ak, sk


def create_app():
    app = web.Application()
    app['prefix'] = 'auth'  # slashed to distinguish with "/vN/authorize"
    app['api_versions'] = (1, 2, 3, 4)
    res = app.router.add_resource(r'')
    res.add_route('GET', auth_test)
    res.add_route('POST', auth_test)
    return app, [auth_middleware]


if __name__ == '__main__':

    def auth_args(parser):
        parser.add('--generate-keypair',
                   action='store_true', default=False,
                   help='Generate a pair of access key and secret key.')

    config = load_config(extra_args_funcs=(auth_args, Logger.update_log_args))
    logger = Logger(config)
    logger.add_pkg('ai.backend')
    with logger:
        if config.generate_keypair:
            ak, sk = generate_keypair()
            print(f'Access Key: {ak} ({len(ak)} bytes)')
            print(f'Secret Key: {sk} ({len(sk)} bytes)')