Esempio n. 1
0
def init_app():
    """Initialise the web server."""
    LOG.info('Initialising web server.')
    app = web.Application(middlewares=[api_key()])
    app.router.add_routes(routes)
    set_cors(app)
    app.on_startup.append(init_db)
    app.on_cleanup.append(close_db)
    return app
Esempio n. 2
0
async def init_db(app):
    """Initialise a database connection pool."""
    LOG.info('Creating database connection pool.')
    app['pool'] = await init_db_pool(
        host=os.environ.get('DB_HOST',
                            CONFIG.registry.get('db_host', 'localhost')),
        port=os.environ.get('DB_PORT', CONFIG.registry.get('db_port', '5432')),
        user=os.environ.get('DB_USER', CONFIG.registry.get('db_user', 'user')),
        passwd=os.environ.get('DB_PASS',
                              CONFIG.registry.get('db_pass', 'pass')),
        db=os.environ.get('DB_NAME', CONFIG.registry.get('db_name', 'db')))
Esempio n. 3
0
def main():
    """Run the web server."""
    LOG.info('Starting server build.')
    web.run_app(init_app(),
                host=os.environ.get(
                    'APP_HOST', CONFIG.aggregator.get('app_host', '0.0.0.0')),
                port=int(
                    os.environ.get('APP_PORT',
                                   CONFIG.aggregator.get('app_port', 8080))),
                shutdown_timeout=0,
                ssl_context=application_security())
Esempio n. 4
0
async def close_db(app):
    """Close the database connection pool."""
    LOG.info('Closing database connection pool.')
    await app['pool'].close()
Esempio n. 5
0
def init_app():
    """Initialise the web server."""
    LOG.info('Initialising web server.')
    app = web.Application(middlewares=[api_key()])
    app.router.add_routes(routes)
    set_cors(app)
    app.on_startup.append(init_db)
    app.on_cleanup.append(close_db)
    return app


def main():
    """Run the web server."""
    LOG.info('Starting server build.')
    web.run_app(init_app(),
                host=os.environ.get('APP_HOST',
                                    CONFIG.registry.get('app_host',
                                                        '0.0.0.0')),
                port=int(
                    os.environ.get('APP_PORT',
                                   CONFIG.registry.get('app_port', 8080))),
                shutdown_timeout=0,
                ssl_context=application_security())


if __name__ == '__main__':
    assert sys.version_info >= (3,
                                6), "This service requires python3.6 or above"
    LOG.info('Starting web server start-up routines.')
    main()