From e79672987e646957aa937242592e0918c2829934 Mon Sep 17 00:00:00 2001 From: "HUGHES, ALEXANDER (ah8742)" Date: Fri, 5 Jul 2019 15:11:14 -0500 Subject: [PATCH] Pegleg Shipyard Auth Token instead of user/pass Recently Shipyard was updated in [0] to allow a user to provide an auth token manually, as an environment variable, instead of having Shipyard obtain a token from Keystone using passed in auth variables including a username and password. This patch expands on that functionality to allow a user to either set an OS_AUTH_TOKEN environment variable, or pass it during the upload command with the --os-auth-token flag. If it is present, only the token is used and the other auth variables are ignored. [0] https://review.opendev.org/#/c/666402/ Change-Id: Iaf2a109022e8f5d496851ff43fcfa8198b5411c9 --- pegleg/cli.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pegleg/cli.py b/pegleg/cli.py index 7e02a4df..e2d10f05 100644 --- a/pegleg/cli.py +++ b/pegleg/cli.py @@ -339,6 +339,7 @@ def collection_default_callback(ctx, param, value): @click.option('--os-username', envvar='OS_USERNAME', required=False) @click.option('--os-password', envvar='OS_PASSWORD', required=False) @click.option('--os-auth-url', envvar='OS_AUTH_URL', required=False) +@click.option('--os-auth-token', envvar='OS_AUTH_TOKEN', required=False) # Option passed to Shipyard client context @click.option( '--context-marker', @@ -370,19 +371,23 @@ def collection_default_callback(ctx, param, value): @click.pass_context def upload(ctx, *, os_project_domain_name, os_user_domain_name, os_project_name, os_username, os_password, os_auth_url, - context_marker, site_name, buffer_mode, collection): + os_auth_token, context_marker, site_name, buffer_mode, collection): if not ctx.obj: ctx.obj = {} # Build API parameters required by Shipyard API Client. - auth_vars = { - 'project_domain_name': os_project_domain_name, - 'user_domain_name': os_user_domain_name, - 'project_name': os_project_name, - 'username': os_username, - 'password': os_password, - 'auth_url': os_auth_url - } + if os_auth_token: + os.environ['OS_AUTH_TOKEN'] = os_auth_token + auth_vars = {'os_auth_token': os_auth_token} + else: + auth_vars = { + 'project_domain_name': os_project_domain_name, + 'user_domain_name': os_user_domain_name, + 'project_name': os_project_name, + 'username': os_username, + 'password': os_password, + 'auth_url': os_auth_url + } ctx.obj['API_PARAMETERS'] = {'auth_vars': auth_vars} ctx.obj['context_marker'] = str(context_marker)