本文整理汇总了Python中keystoneclient.auth.token_endpoint.Token方法的典型用法代码示例。如果您正苦于以下问题:Python token_endpoint.Token方法的具体用法?Python token_endpoint.Token怎么用?Python token_endpoint.Token使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keystoneclient.auth.token_endpoint
的用法示例。
在下文中一共展示了token_endpoint.Token方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_endpoint_from_keystone
# 需要导入模块: from keystoneclient.auth import token_endpoint [as 别名]
# 或者: from keystoneclient.auth.token_endpoint import Token [as 别名]
def _get_endpoint_from_keystone(self, cxt):
auth = token_endpoint.Token(cfg.CONF.client.identity_url,
cxt.auth_token)
sess = session.Session(auth=auth)
cli = keystone_client.Client(session=sess)
service_id_name_map = {}
for service in cli.services.list():
service_dict = service.to_dict()
service_id_name_map[service_dict['id']] = service_dict['name']
region_service_endpoint_map = {}
for endpoint in cli.endpoints.list():
endpoint_dict = endpoint.to_dict()
if endpoint_dict['interface'] != 'public':
continue
region_id = endpoint_dict['region']
service_id = endpoint_dict['service_id']
url = endpoint_dict['url']
service_name = service_id_name_map[service_id]
if region_id not in region_service_endpoint_map:
region_service_endpoint_map[region_id] = {}
region_service_endpoint_map[region_id][service_name] = url
return region_service_endpoint_map
示例2: test_identity_headers_and_token
# 需要导入模块: from keystoneclient.auth import token_endpoint [as 别名]
# 或者: from keystoneclient.auth.token_endpoint import Token [as 别名]
def test_identity_headers_and_token(self):
identity_headers = {
'X-Auth-Token': 'auth_token',
'X-User-Id': 'user',
'X-Tenant-Id': 'tenant',
'X-Roles': 'roles',
'X-Identity-Status': 'Confirmed',
'X-Service-Catalog': 'service_catalog',
}
# with token
kwargs = {'token': u'fake-token',
'identity_headers': identity_headers}
http_client_object = http.HTTPClient(self.endpoint, **kwargs)
self.assertEqual('auth_token', http_client_object.auth_token)
self.assertTrue(http_client_object.identity_headers.
get('X-Auth-Token') is None)
示例3: test_identity_headers_are_passed
# 需要导入模块: from keystoneclient.auth import token_endpoint [as 别名]
# 或者: from keystoneclient.auth.token_endpoint import Token [as 别名]
def test_identity_headers_are_passed(self):
# Tests that if token or X-Auth-Token are not provided in the kwargs
# when creating the http client, the session headers don't contain
# the X-Auth-Token key.
identity_headers = {
'X-User-Id': b'user',
'X-Tenant-Id': b'tenant',
'X-Roles': b'roles',
'X-Identity-Status': b'Confirmed',
'X-Service-Catalog': b'service_catalog',
}
kwargs = {'identity_headers': identity_headers}
http_client = http.HTTPClient(self.endpoint, **kwargs)
path = '/users/user_id'
self.mock.get(self.endpoint + path)
http_client.get(path)
headers = self.mock.last_request.headers
for k, v in six.iteritems(identity_headers):
self.assertEqual(v, headers[k])
示例4: test_expired_token_has_changed
# 需要导入模块: from keystoneclient.auth import token_endpoint [as 别名]
# 或者: from keystoneclient.auth.token_endpoint import Token [as 别名]
def test_expired_token_has_changed(self):
# instantiate client with some token
fake_token = b'fake-token'
http_client = http.HTTPClient(self.endpoint,
token=fake_token)
path = '/users/user_id'
self.mock.get(self.endpoint + path)
http_client.get(path)
headers = self.mock.last_request.headers
self.assertEqual(fake_token, headers['X-Auth-Token'])
# refresh the token
refreshed_token = b'refreshed-token'
http_client.auth_token = refreshed_token
http_client.get(path)
headers = self.mock.last_request.headers
self.assertEqual(refreshed_token, headers['X-Auth-Token'])
# regression check for bug 1448080
unicode_token = u'ni\xf1o'
http_client.auth_token = unicode_token
http_client.get(path)
headers = self.mock.last_request.headers
self.assertEqual(b'ni\xc3\xb1o', headers['X-Auth-Token'])
示例5: __init__
# 需要导入模块: from keystoneclient.auth import token_endpoint [as 别名]
# 或者: from keystoneclient.auth.token_endpoint import Token [as 别名]
def __init__(self, endpoint, **kwargs):
try:
from keystoneclient.v3 import client
from keystoneclient.auth import token_endpoint
from keystoneclient import session
from keystoneclient.auth.identity import v3
except ImportError:
if six.PY2:
apt_install(["python-keystoneclient"], fatal=True)
else:
apt_install(["python3-keystoneclient"], fatal=True)
from keystoneclient.v3 import client
from keystoneclient.auth import token_endpoint
from keystoneclient import session
from keystoneclient.auth.identity import v3
self.api_version = 3
token = kwargs.get("token", None)
if token:
auth = token_endpoint.Token(endpoint=endpoint,
token=token)
sess = session.Session(auth=auth)
else:
auth = v3.Password(auth_url=endpoint,
user_id=kwargs.get("username"),
password=kwargs.get("password"),
project_id=kwargs.get("tenant_name"))
sess = session.Session(auth=auth)
self.api = client.Client(session=sess)
示例6: __init__
# 需要导入模块: from keystoneclient.auth import token_endpoint [as 别名]
# 或者: from keystoneclient.auth.token_endpoint import Token [as 别名]
def __init__(self, endpoint, token):
self.api_version = 3
keystone_auth_v3 = token_endpoint.Token(endpoint=endpoint, token=token)
keystone_session_v3 = session.Session(auth=keystone_auth_v3)
self.api = keystoneclient_v3.Client(session=keystone_session_v3)
示例7: _create_session_client
# 需要导入模块: from keystoneclient.auth import token_endpoint [as 别名]
# 或者: from keystoneclient.auth.token_endpoint import Token [as 别名]
def _create_session_client(self):
auth = token_endpoint.Token(self.endpoint, self.token)
sess = session.Session(auth=auth)
return http.SessionClient(sess)
示例8: test_identity_headers_and_no_token_in_header
# 需要导入模块: from keystoneclient.auth import token_endpoint [as 别名]
# 或者: from keystoneclient.auth.token_endpoint import Token [as 别名]
def test_identity_headers_and_no_token_in_header(self):
identity_headers = {
'X-User-Id': 'user',
'X-Tenant-Id': 'tenant',
'X-Roles': 'roles',
'X-Identity-Status': 'Confirmed',
'X-Service-Catalog': 'service_catalog',
}
# without X-Auth-Token in identity headers
kwargs = {'token': u'fake-token',
'identity_headers': identity_headers}
http_client_object = http.HTTPClient(self.endpoint, **kwargs)
self.assertEqual(u'fake-token', http_client_object.auth_token)
self.assertTrue(http_client_object.identity_headers.
get('X-Auth-Token') is None)
示例9: test_identity_headers_and_no_token_in_session_header
# 需要导入模块: from keystoneclient.auth import token_endpoint [as 别名]
# 或者: from keystoneclient.auth.token_endpoint import Token [as 别名]
def test_identity_headers_and_no_token_in_session_header(self):
# Tests that if token or X-Auth-Token are not provided in the kwargs
# when creating the http client, the session headers don't contain
# the X-Auth-Token key.
identity_headers = {
'X-User-Id': 'user',
'X-Tenant-Id': 'tenant',
'X-Roles': 'roles',
'X-Identity-Status': 'Confirmed',
'X-Service-Catalog': 'service_catalog',
}
kwargs = {'identity_headers': identity_headers}
http_client_object = http.HTTPClient(self.endpoint, **kwargs)
self.assertIsNone(http_client_object.auth_token)
self.assertNotIn('X-Auth-Token', http_client_object.session.headers)
示例10: _get_session
# 需要导入模块: from keystoneclient.auth import token_endpoint [as 别名]
# 或者: from keystoneclient.auth.token_endpoint import Token [as 别名]
def _get_session(self, admauth=None, token=None, cert=None):
try:
if not self.auth_session:
if token:
self.logger.debug("Getting auth session using token")
auth = ks_token.Token(endpoint=self.auth_url, token=token)
elif admauth:
self.logger.debug("Getting session using admin credentials")
auth = ks_auth.Password(
auth_url=self.auth_url,
username=admauth['username'],
password=admauth['password'],
project_name=admauth['project_name'],
user_domain_name=admauth['user_domain_name'],
project_domain_name=admauth['project_domain_name'])
else:
msg = "Token or auth settings not defined"
self.logger.error(msg)
raise ValueError(msg)
verify = cert != None
self.auth_session = ks_session.Session(
auth=auth, verify=verify, cert=cert)
self.logger.debug(
"New session defined: '%s'" % (self.auth_session))
return self.auth_session
except ks_exceptions.ClientException as e:
self.logger.error("Problem getting session: %s" % e)
raise