• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python helpers.get_auth_header函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mist.io.helpers.get_auth_header函数的典型用法代码示例。如果您正苦于以下问题:Python get_auth_header函数的具体用法?Python get_auth_header怎么用?Python get_auth_header使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_auth_header函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: update_user_settings

def update_user_settings(request):
    """try free plan, by communicating to the mist.core service"""

    params = request.json_body
    action = params.get('action', '').lower()
    plan = params.get('plan', '')
    name = params.get('name', '')
    company_name = params.get('company_name', '')
    country = params.get('country', '')
    number_of_servers = params.get('number_of_servers', '')
    number_of_people = params.get('number_of_people', '')

    user = user_from_request(request)

    payload = {'action': action,
               'plan': plan,
               'name': name,
               'company_name': company_name,
               'country': country,
               'number_of_servers': number_of_servers,
               'number_of_people': number_of_people}

    try:
        ret = requests.post(config.CORE_URI + '/account',
                            params=payload,
                            headers={'Authorization': get_auth_header(user)},
                            verify=config.SSL_VERIFY)
    except requests.exceptions.SSLError as exc:
        log.error("%r", exc)
        raise SSLError()
    if ret.status_code == 200:
        ret = json.loads(ret.content)
        return ret
    else:
        raise UnauthorizedError()
开发者ID:johnnyWalnut,项目名称:mist.io,代码行数:35,代码来源:views.py


示例2: get_loadavg

def get_loadavg(request, action=None):
    """Get the loadavg png displayed in the machines list view."""
    params = request.params
    start = params.get('start', '')
    stop = params.get('stop', '')
    user = user_from_request(request)
    core_uri = config.CORE_URI
    payload = {
        'start': start,
        'stop': stop,
    }
    headers = {
        'Authorization': get_auth_header(user),
        'Content-type': 'image/png',
        'Accept': '*/*'
    }
    try:
        ret = requests.get(config.CORE_URI + request.path, params=payload,
                           headers=headers, verify=config.SSL_VERIFY)
    except requests.exceptions.SSLError as exc:
        log.error("%r", exc)
        raise SSLError()
    if ret.status_code != 200:
        log.error("Error getting loadavg %d:%s", ret.status_code, ret.text)
        raise ServiceUnavailableError()
    return Response(ret.content, content_type='image/png', request=request)
开发者ID:deanet,项目名称:mist.io,代码行数:26,代码来源:views.py


示例3: get_stats

def get_stats(request):
    core_uri = config.CORE_URI
    user = user_from_request(request)
    params = request.params
    start = params.get('start')
    stop = params.get('stop')
    step = params.get('step')
    expression = params.get('expression')

    params = {
        'start': start,
        'stop': stop,
        'step': step,
        'expression': expression,
    }
    try:
        ret = requests.get(config.CORE_URI + request.path,
                           params=params,
                           headers={'Authorization': get_auth_header(user)},
                           verify=config.SSL_VERIFY)
    except requests.exceptions.SSLError as exc:
        log.error("%r", exc)
        raise SSLError()
    if ret.status_code == 200:
        return ret.json()
    else:
        log.error("Error getting stats %d:%s", ret.status_code, ret.text)
        raise ServiceUnavailableError()
开发者ID:AnyBucket,项目名称:mist.io,代码行数:28,代码来源:views.py


示例4: check_monitoring

def check_monitoring(request):
    """Ask the mist.io service if monitoring is enabled for this machine.

    """
    user = user_from_request(request)

    ret = requests.get(config.CORE_URI + request.path,
                       headers={'Authorization': get_auth_header(user)},
                       verify=False)
    if ret.status_code == 200:
        return ret.json()
    else:
        log.error("Error getting stats %d:%s", ret.status_code, ret.text)
        raise ServiceUnavailableError()
开发者ID:smeverts,项目名称:mist.io,代码行数:14,代码来源:views.py


示例5: delete_rule

def delete_rule(request):
    """Deletes a rule.

    """
    user = user_from_request(request)
    #TODO: make ssl verification configurable globally, set to true by default
    ret = requests.delete(
        config.CORE_URI + request.path,
        headers={'Authorization': get_auth_header(user)},
        verify=False
    )

    if ret.status_code != 200:
        log.error("Error deleting rule %d:%s", ret.status_code, ret.text)
        raise ServiceUnavailableError()

    return OK
开发者ID:smeverts,项目名称:mist.io,代码行数:17,代码来源:views.py


示例6: delete_rule

def delete_rule(request):
    """Deletes a rule.

    """
    user = user_from_request(request)
    try:
        ret = requests.delete(
            config.CORE_URI + request.path,
            headers={'Authorization': get_auth_header(user)},
            verify=config.SSL_VERIFY
        )
    except requests.exceptions.SSLError as exc:
        log.error("%r", exc)
        raise SSLError()
    if ret.status_code != 200:
        log.error("Error deleting rule %d:%s", ret.status_code, ret.text)
        raise ServiceUnavailableError()
    trigger_session_update(user.email, ['monitoring'])
    return OK
开发者ID:johnnyWalnut,项目名称:mist.io,代码行数:19,代码来源:views.py


示例7: update_rule

def update_rule(request):
    """Creates or updates a rule.

    """
    user = user_from_request(request)
    try:
        ret = requests.post(
            config.CORE_URI + request.path,
            params=request.json_body,
            headers={'Authorization': get_auth_header(user)},
            verify=config.SSL_VERIFY
        )
    except requests.exceptions.SSLError as exc:
        log.error("%r", exc)
        raise SSLError()
    if ret.status_code != 200:
        log.error("Error updating rule %d:%s", ret.status_code, ret.text)
        raise ServiceUnavailableError()
    return ret.json()
开发者ID:AnyBucket,项目名称:mist.io,代码行数:19,代码来源:views.py


示例8: get_stats

def get_stats(request):
    core_uri = config.CORE_URI
    user = user_from_request(request)
    params = request.params
    start = params.get('start', '')
    stop = params.get('stop', '')
    step = params.get('step', '')
    expression = params.get('expression', '')

    payload = {
        'start': start,
        'stop': stop,
        'step': step,
        'expression': expression
    }
    ret = requests.get(config.CORE_URI + request.path,
                       params=payload,
                       headers={'Authorization': get_auth_header(user)},
                       verify=False)
    if ret.status_code == 200:
        return ret.json()
    else:
        log.error("Error getting stats %d:%s", ret.status_code, ret.text)
        raise ServiceUnavailableError()
开发者ID:smeverts,项目名称:mist.io,代码行数:24,代码来源:views.py


示例9: main

def main(global_config, **settings):
    """This function returns a Pyramid WSGI application."""
    if not settings.keys():
        settings = global_config

    settings = {}
    from mist.io.model import User

    # migrate settings.yaml to db.yaml
    try:
        with open('settings.yaml', 'r') as config_file:
            log.info("Found settings.yaml, migrating...")
            data = config_file.read()
            with open('db.yaml', 'w') as db_file:
                db_file.write(data)
        os.rename('settings.yaml', 'settings.yaml.backup')
        user = User()
        with user.lock_n_load():
            for key in ['core_uri', 'js_build', 'js_log_level']:
                if key in user._dict:
                    del user._dict[key]
            user.save()

        from mist.io.model import Machine
        with user.lock_n_load():
            for backend in user.backends.values():
                if 'list_of_machines' in backend._dict:
                    list_of_machines = backend._dict['list_of_machines']
                    for old_machine in list_of_machines:
                        machine_id = old_machine.get('id')
                        machine_hostname = old_machine.get('hostname')
                        print ("Migrating %s(%s) for user %s" %
                               (machine_id, machine_hostname, user.email))
                        if not machine_id or not machine_hostname:
                            print " *** ERROR MIGRATING, SKIPPING *** "
                            continue
                        if machine_id not in backend.machines:
                            backend.machines[machine_id] = Machine()
                        machine = backend.machines[machine_id]
                        machine.dns_name = machine_hostname
                        machine.public_ips.append(machine_hostname)
                        machine.name = machine_hostname
                    del backend._dict['list_of_machines']
            user.save()
    except IOError as exc:
        # settings.yaml doesn't exist, continue
        pass

    user = User()   # this automatically loads from db.yaml
    # try to authenticate with mist.io service if email,password are available
    if user.email and user.mist_api_token:
        from mist.io.helpers import get_auth_header
        ret = requests.post(mist.io.config.CORE_URI + '/auth',
                            headers={'Authorization': get_auth_header(user)},
                            verify=False)
        if ret.status_code == 200:
            log.info("Succesfully authenticated to mist.io service.")
            ret = json.loads(ret.content)
            settings['current_plan'] = ret.get('current_plan', {})
            settings['auth_key'] = ret.get('auth_key', '')
            ## # FIXME: do we really need the following params?
            ## user_details = ret.get('user_details', {})
            ## settings['user']['name'] = user_details.get('name', '')
            ## settings['user']['company_name'] = user_details.get('company_name', '')
            ## settings['user']['country'] = user_details.get('country', '')
            ## settings['user']['number_of_servers'] = user_details.get('number_of_servers', '')
            ## settings['user']['number_of_people'] = user_details.get('number_of_people', '')
        else:
            log.error("Error authenticating to mist.io service. %d: %s", ret.status_code, ret.text)
            settings['auth'] = False

    config = Configurator(root_factory=Root, settings=settings)
    config.add_static_view('resources', 'mist.io:static')
    config.add_static_view('docs', path='../../../docs/build')
    config.include(add_routes)
    config.scan()
    app = config.make_wsgi_app()

    return app
开发者ID:smeverts,项目名称:mist.io,代码行数:79,代码来源:__init__.py



注:本文中的mist.io.helpers.get_auth_header函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python helpers.params_from_request函数代码示例发布时间:2022-05-27
下一篇:
Python helpers.user_from_request函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap