Add support domain-scoped token for CLI

Change-Id: I4c0b4a6de9598e234e0b49b9cfc0b4dc5daaf7be
This commit is contained in:
Svetlana Shturm 2019-08-01 21:36:50 -05:00
parent 1472a22dce
commit d8332bcebb
3 changed files with 29 additions and 5 deletions

View File

@ -32,6 +32,8 @@ variables that will be used are as follows:
- OS_PROJECT_DOMAIN_NAME ("default" if not specified)
- OS_USER_DOMAIN_NAME ("default" if not specified)
- OS_DOMAIN_NAME
- OS_AUTH_TOKEN
- OS_PROJECT_NAME
- OS_USERNAME
- OS_PASSWORD

View File

@ -150,6 +150,9 @@ class BaseClient(metaclass=abc.ABCMeta):
def _get_ks_session(self):
self.logger.debug('Accessing keystone for keystone session')
try:
if self.context.keystone_auth.get("token"):
auth = v3.Token(**self.context.keystone_auth)
else:
auth = v3.Password(**self.context.keystone_auth)
return session.Session(auth=auth)
except AuthorizationFailure as e:

View File

@ -46,10 +46,16 @@ from shipyard_client.cli.input_checks import check_control_action, check_id
type=click.Choice(['format', 'raw', 'cli']),
default='cli')
# Supported Environment Variables
@click.option('--os-auth-token',
envvar='OS_AUTH_TOKEN',
required=False)
@click.option('--os-project-domain-name',
envvar='OS_PROJECT_DOMAIN_NAME',
required=False,
default='default')
@click.option('--os-domain-name',
envvar='OS_DOMAIN_NAME',
required=False)
@click.option('--os-user-domain-name',
envvar='OS_USER_DOMAIN_NAME',
required=False,
@ -68,9 +74,9 @@ from shipyard_client.cli.input_checks import check_control_action, check_id
type=click.IntRange(0, 5),
default=1)
@click.pass_context
def shipyard(ctx, context_marker, debug, os_project_domain_name,
os_user_domain_name, os_project_name, os_username, os_password,
os_auth_url, output_format, verbosity):
def shipyard(ctx, context_marker, debug, os_auth_token, os_project_domain_name,
os_user_domain_name, os_domain_name, os_project_name, os_username,
os_password, os_auth_url, output_format, verbosity):
"""
COMMAND: shipyard \n
DESCRIPTION: The base shipyard command supports options that determine
@ -95,7 +101,6 @@ def shipyard(ctx, context_marker, debug, os_project_domain_name,
logger.debug('logging for cli initialized')
auth_vars = {
'project_domain_name': os_project_domain_name,
'user_domain_name': os_user_domain_name,
'project_name': os_project_name,
'username': os_username,
@ -103,6 +108,20 @@ def shipyard(ctx, context_marker, debug, os_project_domain_name,
'auth_url': os_auth_url
}
if os_auth_token:
auth_vars = {
'token': os_auth_token,
'auth_url': os_auth_url
}
# Domain-scoped params
if os_domain_name:
auth_vars['domain_name'] = os_domain_name
auth_vars['project_domain_name'] = None
# Project-scoped params
else:
auth_vars['project_domain_name'] = os_project_domain_name
ctx.obj['API_PARAMETERS'] = {
'auth_vars': auth_vars,
'context_marker': str(context_marker) if context_marker else None,