Exemplo n.º 1
0
    async def __init__(self,
                       billing_project,
                       deploy_config=None,
                       session=None,
                       headers=None,
                       _token=None):
        self.billing_project = billing_project

        if not deploy_config:
            deploy_config = get_deploy_config()

        self.url = deploy_config.base_url('batch')

        if session is None:
            session = ssl_client_session(
                raise_for_status=True, timeout=aiohttp.ClientTimeout(total=60))
        self._session = session

        userinfo = await async_get_userinfo(deploy_config)
        self.bucket = userinfo['bucket_name']

        h = {}
        if headers:
            h.update(headers)
        if _token:
            h['Authorization'] = f'Bearer {_token}'
        else:
            h.update(service_auth_headers(deploy_config, 'batch'))
        self._headers = h
Exemplo n.º 2
0
async def async_get_userinfo(deploy_config=None, headers=None):
    if deploy_config is None:
        deploy_config = get_deploy_config()
    if headers is None:
        headers = service_auth_headers(deploy_config, 'auth')
    userinfo_url = deploy_config.url('auth', '/api/v1alpha/userinfo')
    async with ssl_client_session(
            raise_for_status=True, timeout=aiohttp.ClientTimeout(total=5)) as session:
        resp = await request_retry_transient_errors(
            session, 'GET', userinfo_url, headers=headers)
        return await resp.json()
Exemplo n.º 3
0
async def async_main(args):
    deploy_config = get_deploy_config()
    if args.namespace:
        auth_ns = args.namespace
        deploy_config = deploy_config.with_service('auth', auth_ns)
    else:
        auth_ns = deploy_config.service_ns('auth')
    headers = namespace_auth_headers(deploy_config,
                                     auth_ns,
                                     authorize_target=False)
    async with ssl_client_session(raise_for_status=True,
                                  timeout=aiohttp.ClientTimeout(total=60),
                                  headers=headers) as session:
        await auth_flow(deploy_config, auth_ns, session)
Exemplo n.º 4
0
async def async_main():
    deploy_config = get_deploy_config()

    auth_ns = deploy_config.service_ns('auth')
    tokens = get_tokens()
    if auth_ns not in tokens:
        print('Not logged in.')
        return

    headers = service_auth_headers(deploy_config, 'auth')
    async with ssl_client_session(raise_for_status=True,
                                  timeout=aiohttp.ClientTimeout(total=60),
                                  headers=headers) as session:
        async with session.post(
                deploy_config.url('auth', '/api/v1alpha/logout')):
            pass
    auth_ns = deploy_config.service_ns('auth')

    del tokens[auth_ns]
    tokens.write()

    print('Logged out.')
Exemplo n.º 5
0
async def _userdata_from_session_id(session_id):
    headers = {'Authorization': f'Bearer {session_id}'}
    try:
        async with ssl_client_session(
                raise_for_status=True,
                timeout=aiohttp.ClientTimeout(total=5)) as session:
            resp = await request_retry_transient_errors(
                session,
                'GET',
                deploy_config.url('auth', '/api/v1alpha/userinfo'),
                headers=headers)
            assert resp.status == 200
            return await resp.json()
    except aiohttp.ClientResponseError as e:
        if e.status == 401:
            return None

        log.exception('unknown exception getting userinfo')
        raise web.HTTPInternalServerError()
    except Exception:  # pylint: disable=broad-except
        log.exception('unknown exception getting userinfo')
        raise web.HTTPInternalServerError()
Exemplo n.º 6
0
 async def __aenter__(self):
     headers = service_auth_headers(self._deploy_config, 'ci')
     self._session = ssl_client_session(
         raise_for_status=True, timeout=aiohttp.ClientTimeout(total=60), headers=headers)
     return self