Merge "Add support domain-scoped token for CLI"

This commit is contained in:
Zuul 2019-08-07 22:34:14 +00:00 committed by Gerrit Code Review
commit 9c5f68cf97
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_PROJECT_DOMAIN_NAME ("default" if not specified)
- OS_USER_DOMAIN_NAME ("default" if not specified) - OS_USER_DOMAIN_NAME ("default" if not specified)
- OS_DOMAIN_NAME
- OS_AUTH_TOKEN
- OS_PROJECT_NAME - OS_PROJECT_NAME
- OS_USERNAME - OS_USERNAME
- OS_PASSWORD - OS_PASSWORD

View File

@ -150,7 +150,10 @@ class BaseClient(metaclass=abc.ABCMeta):
def _get_ks_session(self): def _get_ks_session(self):
self.logger.debug('Accessing keystone for keystone session') self.logger.debug('Accessing keystone for keystone session')
try: try:
auth = v3.Password(**self.context.keystone_auth) 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) return session.Session(auth=auth)
except AuthorizationFailure as e: except AuthorizationFailure as e:
self.logger.error('Could not authorize against keystone: %s', self.logger.error('Could not authorize against keystone: %s',

View File

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