From fe3629f1bab78664498192efcc9d782d061459f1 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Tue, 19 Nov 2013 16:42:49 +0000 Subject: Fix shell operation with --os-auth-token Currently the --os-auth-token/env[OS_AUTH_TOKEN] case doesn't work, as we always expect a username/password to create the connection to keystone. This enables the client to be used with only a token and tenant (which is required for keystoneclient to retrieve the catalog) specified, e.g: heat --os-auth-url http://127.0.0.1:35357/v2.0/ \ --os-auth-token \ --os-tenant-id stack-list Change-Id: I478ce178f44e42c68153f1b347c6144f0a133f5b Partial-Bug: #1252248 --- heatclient/shell.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'heatclient/shell.py') diff --git a/heatclient/shell.py b/heatclient/shell.py index 56ce087..b254964 100644 --- a/heatclient/shell.py +++ b/heatclient/shell.py @@ -219,15 +219,22 @@ class HeatShell(object): :param tenant_id: unique identifier of tenant :param tenant_name: name of tenant :param auth_url: endpoint to authenticate against + :param token: token to use instead of username/password """ kc_args = {'auth_url': kwargs.get('auth_url'), - 'insecure': kwargs.get('insecure'), - 'username': kwargs.get('username'), - 'password': kwargs.get('password')} + 'insecure': kwargs.get('insecure')} + if kwargs.get('tenant_id'): kc_args['tenant_id'] = kwargs.get('tenant_id') else: kc_args['tenant_name'] = kwargs.get('tenant_name') + + if kwargs.get('token'): + kc_args['token'] = kwargs.get('token') + else: + kc_args['username'] = kwargs.get('username') + kc_args['password'] = kwargs.get('password') + return ksclient.Client(**kc_args) def _get_endpoint(self, client, **kwargs): @@ -280,18 +287,22 @@ class HeatShell(object): self.do_help(args) return 0 - if not args.os_username: + if not args.os_username and not args.os_auth_token: raise exc.CommandError("You must provide a username via" - " either --os-username or env[OS_USERNAME]") + " either --os-username or env[OS_USERNAME]" + " or a token via --os-auth-token or" + " env[OS_AUTH_TOKEN]") - if not args.os_password: + if not args.os_password and not args.os_auth_token: raise exc.CommandError("You must provide a password via" - " either --os-password or env[OS_PASSWORD]") + " either --os-password or env[OS_PASSWORD]" + " or a token via --os-auth-token or" + " env[OS_AUTH_TOKEN]") if not (args.os_tenant_id or args.os_tenant_name): raise exc.CommandError("You must provide a tenant_id via" - " either --os-tenant-id or via " - "env[OS_TENANT_ID]") + " either --os-tenant-id or via" + " env[OS_TENANT_ID]") if not args.os_auth_url: raise exc.CommandError("You must provide an auth url via" @@ -305,6 +316,7 @@ class HeatShell(object): kwargs = { 'username': args.os_username, 'password': args.os_password, + 'token': args.os_auth_token, 'tenant_id': args.os_tenant_id, 'tenant_name': args.os_tenant_name, 'auth_url': args.os_auth_url, -- cgit v1.2.1