1 ##############################################################################
2 # Copyright (c) 2017 NEC Corporation and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 from keystoneauth1 import loading
12 from keystoneauth1 import session
15 def get_identity_auth(username=None, password=None, project=None):
16 auth_url = os.environ['OS_AUTH_URL']
17 username = username or os.environ['OS_USERNAME']
18 password = password or os.environ['OS_PASSWORD']
19 user_domain_name = os.environ.get('OS_USER_DOMAIN_NAME') or 'default'
20 user_domain_id = os.environ.get('OS_USER_DOMAIN_ID') or 'default'
21 project_name = project or os.environ.get('OS_PROJECT_NAME') \
22 or os.environ.get('OS_TENANT_NAME')
23 project_domain_name = os.environ.get('OS_PROJECT_DOMAIN_NAME') or 'default'
24 project_domain_id = os.environ.get('OS_PROJECT_DOMAIN_ID') or 'default'
26 loader = loading.get_plugin_loader('password')
27 return loader.load_from_options(
31 user_domain_name=user_domain_name,
32 user_domain_id=user_domain_id,
33 project_name=project_name,
34 tenant_name=project_name,
35 project_domain_name=project_domain_name,
36 project_domain_id=project_domain_id)
39 def get_session(auth=None):
40 """Get a user credentials auth session."""
42 auth = get_identity_auth()
43 return session.Session(auth=auth)