本文整理汇总了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()
示例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)
示例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()
示例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()
示例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
示例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
示例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()
示例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()
示例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