本文整理汇总了Python中astakosclient.AstakosClient.authenticate方法的典型用法代码示例。如果您正苦于以下问题:Python AstakosClient.authenticate方法的具体用法?Python AstakosClient.authenticate怎么用?Python AstakosClient.authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astakosclient.AstakosClient
的用法示例。
在下文中一共展示了AstakosClient.authenticate方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _http_scheme
# 需要导入模块: from astakosclient import AstakosClient [as 别名]
# 或者: from astakosclient.AstakosClient import authenticate [as 别名]
def _http_scheme(self, pool):
global token
http_auth_url = "http://example.org/identity/v2.0"
try:
client = AstakosClient(token['id'], http_auth_url, use_pool=pool)
client.authenticate()
except AstakosClientException as err:
if err.status != 302:
self.fail("Should have returned 302 (Found)")
else:
self.fail("Should have returned 302 (Found)")
示例2: _invalid_token
# 需要导入模块: from astakosclient import AstakosClient [as 别名]
# 或者: from astakosclient.AstakosClient import authenticate [as 别名]
def _invalid_token(self, pool):
global auth_url
token = "skaksaFlBl+fasFdaf24sx"
try:
client = AstakosClient(token, auth_url, use_pool=pool)
client.authenticate()
except Unauthorized:
pass
except Exception:
self.fail("Should have returned 401 (Invalid X-Auth-Token)")
else:
self.fail("Should have returned 401 (Invalid X-Auth-Token)")
示例3: _unsupported_scheme
# 需要导入模块: from astakosclient import AstakosClient [as 别名]
# 或者: from astakosclient.AstakosClient import authenticate [as 别名]
def _unsupported_scheme(self, pool):
global token, auth_url
try:
client = AstakosClient(
token['id'], "ftp://example.com", use_pool=pool)
client.authenticate()
except BadValue:
pass
except Exception:
self.fail("Should have raise BadValue Exception")
else:
self.fail("Should have raise BadValue Exception")
示例4: _auth_user
# 需要导入模块: from astakosclient import AstakosClient [as 别名]
# 或者: from astakosclient.AstakosClient import authenticate [as 别名]
def _auth_user(self, pool):
global token, endpoints_with_info, auth_url
try:
client = AstakosClient(token['id'], auth_url, use_pool=pool)
auth_info = client.authenticate()
except Exception as err:
self.fail("Shouldn't raise an Exception: %s" % err)
self.assertEqual(endpoints_with_info, auth_info)
示例5: user_for_token
# 需要导入模块: from astakosclient import AstakosClient [as 别名]
# 或者: from astakosclient.AstakosClient import authenticate [as 别名]
def user_for_token(token, astakos_auth_url, logger=None):
if token is None:
return None
client = AstakosClient(token, astakos_auth_url,
retry=2, use_pool=True, logger=logger)
try:
return client.authenticate()
except Unauthorized:
return None
示例6: authenticate
# 需要导入模块: from astakosclient import AstakosClient [as 别名]
# 或者: from astakosclient.AstakosClient import authenticate [as 别名]
def authenticate(self):
access_token = None
#A KeyError will be raised if there is no token.
access_token = LocalDataManager().get_token()
try:
s = AstakosClient(access_token, strings.Pithos_AUTHURL)
auth_data = s.authenticate()
username = auth_data['access']['user']['name']
pithos_url = self._get_pithos_public_url(auth_data)
uuid = auth_data['access']['user']['id']
pithosClient = PithosClient(pithos_url, access_token, uuid)
resp = pithosClient.list_containers()
except (AstakosErrors.Unauthorized, faults.InvalidAuth) as e:
raise faults.InvalidAuth('Pithos-Auth')
except (AstakosErrors.AstakosClientException, faults.NetworkError) as e:
raise faults.NetworkError('No internet-Auth')
return (pithosClient, username)
示例7: _pithos_auth
# 需要导入模块: from astakosclient import AstakosClient [as 别名]
# 或者: from astakosclient.AstakosClient import authenticate [as 别名]
def _pithos_auth(self):
access_token = None
dataManager = LocalDataManager()
#A KeyError will be raised if there is no token.
access_token = dataManager.get_credentials('Pithos')
try:
dm = LocalDataManager()
s = AstakosClient(access_token, local.Pithos_AUTHURL)
auth_data = s.authenticate()
pithos_url = self._get_pithos_public_url(auth_data)
uuid = auth_data['access']['user']['id']
pithosClient = CloudyPithosClient(pithos_url, access_token, uuid)
pithosClient.container = dm.get_service_root('Pithos')
#Check if the container saved in the settings exists.
self._call_exceptional(pithosClient)
except (AstakosErrors.Unauthorized, faults.InvalidAuth) as e:
raise faults.InvalidAuth('Pithos-Auth')
except (AstakosErrors.AstakosClientException, faults.NetworkError) as e:
raise faults.NetworkError('No internet-Auth')
return pithosClient
示例8: retrieve_user
# 需要导入模块: from astakosclient import AstakosClient [as 别名]
# 或者: from astakosclient.AstakosClient import authenticate [as 别名]
def retrieve_user(token, astakos_auth_url, logger=None, client_ip=None):
"""Return user_info retrieved from astakos for the given token"""
astakos_url = astakos_auth_url
if astakos_url is None:
try:
astakos_url = settings.ASTAKOS_AUTH_URL
except AttributeError:
if logger:
logger.error("Cannot authenticate without having"
" an Astakos Authentication URL")
raise
if not token:
return None
headers = None
if client_ip:
headers = {'X-Client-IP': client_ip}
astakos = AstakosClient(token, astakos_url, use_pool=True, retry=2,
logger=logger, headers=headers)
user_info = astakos.authenticate()
return user_info
示例9: finish
# 需要导入模块: from astakosclient import AstakosClient [as 别名]
# 或者: from astakosclient.AstakosClient import authenticate [as 别名]
def finish(self, token):
s = AstakosClient(token, strings.Pithos_AUTHURL, logger=logger.logger_factory('astakosclient'))
s.authenticate()
return token
示例10: wrapper
# 需要导入模块: from astakosclient import AstakosClient [as 别名]
# 或者: from astakosclient.AstakosClient import authenticate [as 别名]
def wrapper(request, *args, **kwargs):
try:
# Get the requested serialization format
serialization = get_serialization(
request, format_allowed, serializations[0])
# If guessed serialization is not supported, fallback to
# the default serialization or return an API error in case
# strict serialization flag is set.
if not serialization in serializations:
if strict_serlization:
raise faults.BadRequest(("%s serialization not "
"supported") % serialization)
serialization = serializations[0]
request.serialization = serialization
# Check HTTP method
if http_method and request.method != http_method:
raise faults.NotAllowed("Method not allowed",
allowed_methods=[http_method])
# Get authentication token
request.x_auth_token = None
if token_required or user_required:
token = get_token(request)
if not token:
msg = "Access denied. No authentication token"
raise faults.Unauthorized(msg)
request.x_auth_token = token
# Authenticate
if user_required:
assert(token_required), "Can not get user without token"
astakos_url = astakos_auth_url
if astakos_url is None:
try:
astakos_url = settings.ASTAKOS_AUTH_URL
except AttributeError:
logger.error("Cannot authenticate without having"
" an Astakos Authentication URL")
raise
astakos = AstakosClient(token, astakos_url,
use_pool=True,
retry=2,
logger=logger)
user_info = astakos.authenticate()
request.user_uniq = user_info["access"]["user"]["id"]
request.user = user_info
# Get the response object
response = func(request, *args, **kwargs)
# Fill in response variables
update_response_headers(request, response)
return response
except faults.Fault as fault:
if fault.code >= 500:
django_logger.error("Unexpected API Error: %s",
request.path,
exc_info=sys.exc_info(),
extra={
"status_code": fault.code,
"request": request})
return render_fault(request, fault)
except AstakosClientException as err:
fault = faults.Fault(message=err.message,
details=err.details,
code=err.status)
if fault.code >= 500:
django_logger.error("Unexpected AstakosClient Error: %s",
request.path,
exc_info=sys.exc_info(),
extra={
"status_code": fault.code,
"request": request})
return render_fault(request, fault)
except:
django_logger.error("Internal Server Error: %s", request.path,
exc_info=sys.exc_info(),
extra={
"status_code": '500',
"request": request})
fault = faults.InternalServerError("Unexpected error")
return render_fault(request, fault)