How to use the gear.web_authenticated_developers_only function in gear

To help you get started, we’ve selected a few gear examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hail-is / hail / batch / batch / front_end / front_end.py View on Github external
@web_authenticated_developers_only()
async def ui_get_billing_projects(request, userdata):
    db = request.app['db']

    billing_projects = {}
    async with db.start(read_only=True) as tx:
        async for record in tx.execute_and_fetchall(
                'SELECT * FROM billing_projects;'):
            name = record['name']
            billing_projects[name] = []
        async for record in tx.execute_and_fetchall(
                'SELECT * FROM billing_project_users;'):
            billing_project = record['billing_project']
            user = record['user']
            billing_projects[billing_project].append(user)
    page_context = {
        'billing_projects': billing_projects
github hail-is / hail / batch / batch / driver / main.py View on Github external
@web_authenticated_developers_only()
async def config_update(request, userdata):  # pylint: disable=unused-argument
    app = request.app
    inst_pool = app['inst_pool']

    session = await aiohttp_session.get_session(request)

    def validate(name, value, predicate, description):
        if not predicate(value):
            set_message(session,
                        f'{name} invalid: {value}.  Must be {description}.',
                        'error')
            raise web.HTTPFound(deploy_config.external_url('batch-driver', '/'))
        return value

    def validate_int(name, value, predicate, description):
        try:
github hail-is / hail / notebook / notebook / notebook.py View on Github external
@web_authenticated_developers_only()
async def delete_workshop(request, userdata):  # pylint: disable=unused-argument
    app = request.app
    dbpool = app['dbpool']

    post = await request.post()
    name = post['name']
    async with dbpool.acquire() as conn:
        async with conn.cursor() as cursor:
            n = await cursor.execute('''
DELETE FROM workshops WHERE name = %s;
''', name)

    session = await aiohttp_session.get_session(request)
    if n == 1:
        set_message(session, f'Deleted workshop {name}.', 'info')
    else:
github hail-is / hail / auth / auth / auth.py View on Github external
@web_authenticated_developers_only()
async def delete_user(request, userdata):  # pylint: disable=unused-argument
    session = await aiohttp_session.get_session(request)
    dbpool = request.app['dbpool']
    post = await request.post()
    id = post['id']
    username = post['username']

    async with dbpool.acquire() as conn:
        async with conn.cursor() as cursor:
            n_rows = await cursor.execute(
                '''
UPDATE users
SET state = 'deleting'
WHERE id = %s AND username = %s;
''',
                (id, username))
github hail-is / hail / ci / ci / ci.py View on Github external
@web_authenticated_developers_only()
async def index(request, userdata):  # pylint: disable=unused-argument
    app = request.app
    dbpool = app['dbpool']
    wb_configs = []
    for i, wb in enumerate(watched_branches):
        if wb.prs:
            pr_configs = []
            for pr in wb.prs.values():
                batch_id = pr.batch.id if pr.batch and hasattr(pr.batch, 'id') else None
                build_state = pr.build_state if await pr.authorized(dbpool) else 'unauthorized'
                if build_state is None and batch_id is not None:
                    build_state = 'building'

                pr_config = {
                    'number': pr.number,
                    'title': pr.title,
github hail-is / hail / batch / batch / front_end / front_end.py View on Github external
@web_authenticated_developers_only(redirect=False)
async def post_billing_projects_add_user(request, userdata):  # pylint: disable=unused-argument
    db = request.app['db']
    post = await request.post()
    user = post['user']
    billing_project = request.match_info['billing_project']

    session = await aiohttp_session.get_session(request)

    async with db.start() as tx:
        row = await tx.execute_and_fetchone(
            '''
SELECT billing_projects.name as billing_project, user
FROM billing_projects
LEFT JOIN (SELECT * FROM billing_project_users
    WHERE billing_project = %s AND user = %s) AS t
  ON billing_projects.name = t.billing_project
github hail-is / hail / ci / ci / ci.py View on Github external
@web_authenticated_developers_only(redirect=False)
async def post_authorized_source_sha(request, userdata):  # pylint: disable=unused-argument
    app = request.app
    dbpool = app['dbpool']
    post = await request.post()
    sha = post['sha'].strip()
    async with dbpool.acquire() as conn:
        async with conn.cursor() as cursor:
            await cursor.execute('INSERT INTO authorized_shas (sha) VALUES (%s);', sha)
    log.info(f'authorized sha: {sha}')
    session = await aiohttp_session.get_session(request)
    set_message(session, f'SHA {sha} authorized.', 'info')
    raise web.HTTPFound('/')
github hail-is / hail / notebook2 / notebook / notebook.py View on Github external
@web_authenticated_developers_only()
async def workshop_admin(request, userdata):
    app = request.app
    dbpool = app['dbpool']
    context = base_context(deploy_config, userdata, 'notebook2')

    async with dbpool.acquire() as conn:
        async with conn.cursor() as cursor:
            await cursor.execute('SELECT * FROM workshops')
            workshops = await cursor.fetchall()
    context['workshops'] = workshops
    return context