Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
project_name=None,
user_domain_name=None,
project_domain_name=None,
cert=None):
# TODO(agromov): replace params usage with credentials fixture
auth_url = auth_url or config.AUTH_URL
username = username or credentials.username
password = password or credentials.password
project_name = project_name or credentials.project_name
user_domain_name = user_domain_name or credentials.user_domain_name
project_domain_name = (project_domain_name or
credentials.project_domain_name)
if config.KEYSTONE_API_VERSION == 3:
auth = identity.v3.Password(
auth_url=auth_url,
username=username,
user_domain_name=user_domain_name,
password=password,
project_name=project_name,
project_domain_name=project_domain_name)
elif config.KEYSTONE_API_VERSION == 2:
auth = identity.v2.Password(
auth_url=auth_url,
username=username,
password=password,
tenant_name=project_name)
else:
def create_ost_auth_session(deploy):
# type: (Deploy) -> session.Session
""" Create a keystoneauth Session object using keystone v3 used to create Openstack API clients.
:return: Session used to authenticate with various Openstack API clients.
"""
if deploy.auth_version == 2:
auth = v2.Password(auth_url=deploy.openstack_auth_url,
username=deploy.ost_username,
password=deploy.ost_password,
tenant_name=deploy.ost_project_name)
elif deploy.auth_version == 3:
if deploy.ost_project_id:
auth = v3.Password(auth_url=deploy.openstack_auth_url,
username=deploy.ost_username,
password=deploy.ost_password,
project_id=deploy.ost_project_id)
else:
auth = v3.Password(auth_url=deploy.openstack_auth_url,
username=deploy.ost_username,
password=deploy.ost_password,
project_name=deploy.ost_project_name,
user_domain_name=deploy.ost_domain,
project_domain_name=deploy.ost_domain)
else:
raise ConfigException("auth_version must be in [2,3]")
return session.Session(auth=auth, verify=deploy.cacert)
user_domain_name=None, domain_name=None,
project_domain_name=None, project_name=None):
"""Return a keystone session object"""
ep = self.get_keystone_endpoint(keystone_ip,
api_version=api_version,
admin_port=admin_port)
if api_version == 2:
auth = v2.Password(
username=username,
password=password,
tenant_name=project_name,
auth_url=ep
)
sess = keystone_session.Session(auth=auth)
else:
auth = v3.Password(
user_domain_name=user_domain_name,
username=username,
password=password,
domain_name=domain_name,
project_domain_name=project_domain_name,
project_name=project_name,
auth_url=ep
)
sess = keystone_session.Session(auth=auth)
return (sess, auth)
def get_session():
"""Get an initialized keystone session.
Authentication is based on the keystone_authtoken section of the config file.
"""
auth_info = dict()
for f in [
'auth_url', 'username', 'password', 'project_id',
'user_domain_name'
]:
auth_info[f] = getattr(config.config_mgr.conf.keystone_authtoken,
f)
auth = v3.Password(**auth_info)
return session.Session(auth=auth)
def _get_from_deckhand(design_ref, ctx=None):
keystone_args = {}
for attr in ('auth_url', 'password', 'project_domain_name', 'project_name',
'username', 'user_domain_name'):
keystone_args[attr] = cfg.CONF.get('keystone_authtoken', {}).get(attr)
if ctx is not None:
addl_headers = {
'X-CONTEXT-MARKER': ctx.context_marker,
'X-END-USER': ctx.end_user
}
else:
addl_headers = {}
auth = keystoneauth1.identity.v3.Password(**keystone_args)
session = keystoneauth1.session.Session(
auth=auth, additional_headers=addl_headers)
return session.get(design_ref[len(_DECKHAND_PREFIX):], timeout=DH_TIMEOUT)
:returns: a password auth plugin object.
'''
passwd_kwargs = dict(
auth_url=CONF.trustee.auth_url,
username=username,
password=password
)
if CONF.use_identity_api_v3:
passwd_kwargs.update(dict(
project_name=project_name,
user_domain_name=user_domain_name,
project_domain_name=project_domain_name,
trust_id=trust_id
))
auth = keystone_identity.v3.Password(**passwd_kwargs)
else:
passwd_kwargs.update(dict(
tenant_name=project_name,
trust_id=trust_id
))
auth = keystone_identity.v2.Password(**passwd_kwargs)
return auth
if ctx is None:
try:
ctx = context.current()
except RuntimeError:
pass
if ctx is not None:
kwargs.setdefault('global_request_id', ctx.global_request_id)
if auth_url is None:
auth_url = "%s://%s:%s/%s/%s" % (CONF.os_auth_protocol,
base.get_os_auth_host(CONF),
CONF.os_auth_port,
CONF.os_auth_prefix,
CONF.os_auth_version)
auth = v3.Password(auth_url=auth_url,
username=username,
password=password,
project_name=project_name,
user_domain_name=user_domain_name,
project_domain_name=project_domain_name)
sess = session.Session(auth=auth)
# Set accept header on every request to ensure we notify placement
# service of our response body media type preferences.
headers = {'accept': 'application/json'}
kwargs.setdefault('service_type', 'placement')
kwargs.setdefault('interface', 'public')
kwargs.setdefault('additional_headers', headers)
kwargs.setdefault('region_name', region_name)
client = adapter.Adapter(sess, **kwargs)
return client
project_name=None,
project_domain_name="default",
user_domain_name="default",
project_domain_id="default",
user_domain_id="default",
username=None,
password=None):
"""Method return a glance client."""
if auth_url.endswith("/v3/"):
auth_url = auth_url[-1]
elif auth_url.endswith("/v3"):
pass
else:
auth_url = "{}/v3".format(auth_url)
auth = v3.Password(auth_url=auth_url,
project_name=project_name,
project_domain_name=project_domain_name,
user_domain_name=user_domain_name,
project_domain_id=project_domain_id,
user_domain_id=user_domain_id,
username=username,
password=password)
return Client("2", auth_url=CONF.user.endpoint,
session=session.Session(auth=auth))
def get_ks_session(**kwargs):
# Establishes a keystone session
if 'token' in kwargs:
auth = v3.TokenMethod(token=kwargs.get('token'))
else:
auth = v3.Password(**kwargs)
return session.Session(auth=auth)
def _get_auth_plugin(auth_url, **kwargs):
kwargs = {
'username': kwargs.get('username'),
'password': kwargs.get('password'),
'project_name': kwargs.get('project_name'),
'project_domain_id': kwargs.get('project_domain_id'),
'user_domain_id': kwargs.get('user_domain_id'),
}
return v3.Password(auth_url=auth_url, **kwargs)