Example #1
0
async def on_startup(app: web.Application) -> None:
    await init_rpc(app)

    aiohttp_jinja2.setup(app,
                         loader=jinja2.FileSystemLoader("iomirea/templates"))

    # support for X-Forwarded headers
    await aiohttp_remotes.setup(app, aiohttp_remotes.XForwardedRelaxed())

    max_cookie_age = 2592000  # 30 days
    aiohttp_session.setup(app,
                          RedisStorage(app["rd_conn"], max_age=max_cookie_age))

    await EventEmitter.setup_emitter(app)
Example #2
0
def get_app(args):
    logger = utils.configure_logger("doh-httpproxy", args.level)
    app = DOHApplication(logger=logger, debug=args.debug)
    app.set_upstream_resolver(args.upstream_resolver, args.upstream_port)
    app.set_ecs(args.ecs)
    app.router.add_get(args.uri, doh1handler)
    app.router.add_post(args.uri, doh1handler)

    # Get trusted reverse proxies and format it for aiohttp_remotes setup
    if len(args.trusted) == 0:
        x_forwarded_handling = aiohttp_remotes.XForwardedRelaxed()
    else:
        x_forwarded_handling = aiohttp_remotes.XForwardedStrict([args.trusted])

    asyncio.ensure_future(aiohttp_remotes.setup(app, x_forwarded_handling))
    return app
Example #3
0
async def make_app(args):
    cfg = toml.load(args.cfg)
    app = web.Application()

    app.add_routes(auth_route)
    app.add_routes(smarthome_route)
    if args.debug:
        app.add_routes(debug_route)

    if args.proxy:
        await aiohttp_remotes.setup(
            app,
            aiohttp_remotes.XForwardedRelaxed(),
        )
    db.setup(app, f'sqlite:///{args.db}')
    oauth.setup(app)
    aiohttp_jinja2.setup(
        app, loader=aiohttp_jinja2.jinja2.FileSystemLoader('static'))
    aiohttp_jinja2.get_env(app).globals.update(
        url_for=lambda path: app.router[path].url_for(),
        DEBUG=args.debug,
    )

    db_session = db.session_maker()
    cookie_key = db_session.query(
        db.ServerSettings).filter_by(option='cookie_key').first()
    if not cookie_key:
        cookie_key = db.ServerSettings()
        cookie_key.option = 'cookie_key'
        cookie_key.value = open('/dev/urandom', 'rb').read(32)
        db_session.add(cookie_key)
        db_session.commit()

    aiohttp_session.setup(app, EncryptedCookieStorage(cookie_key.value))
    auth.setup(app)

    mqtt_client = MqttClient.from_config(cfg['mqtt'])
    app['mqtt_client'] = asyncio.create_task(mqtt_client.run())

    app['smarthome_devices'] = {}

    if 'notifications' in cfg:
        app['notifications'] = notifications.Notifications(
            skill_id=cfg['notifications']['skill_id'],
            user_id=cfg['notifications']['user_id'],
            oauth_token=cfg['notifications']['oauth_token'],
        )
        app.on_startup.append(lambda app: app['notifications'].
                              send_device_specifications_updated())

    for device_id, device_spec in cfg['devices'].items():
        device_class = device_spec.pop('_class')
        device_spec['device_id'] = device_id

        mqtt_used = device_spec.pop('_mqtt_used', False)
        if mqtt_used:
            device_spec['mqtt_client'] = mqtt_client

        klass = device_classes[device_class]
        app['smarthome_devices'][device_id] = klass(**device_spec)

    app.on_startup.append(start_tasks)

    main_app = web.Application()
    main_app.add_subapp(args.prefix, app)
    return main_app
async def on_startup(app):
    await aiohttp_remotes.setup(app, aiohttp_remotes.XForwardedRelaxed())
    app.http_session_pool = ClientSession(timeout=ClientTimeout(total=30))
    saml.fetch_settings(app)
Example #5
0
async def on_startup(app: web.Application) -> None:
    await aiohttp_remotes.setup(app, aiohttp_remotes.XForwardedRelaxed())