diff options
| author | Steve Martinelli <stevemar@ca.ibm.com> | 2015-01-16 02:20:52 -0500 |
|---|---|---|
| committer | Steve Martinelli <stevemar@ca.ibm.com> | 2015-01-16 02:41:24 -0500 |
| commit | fff4a1cd23057160af13f157a6fde2c172fae7a9 (patch) | |
| tree | 451c53610a9fef84e92fb723907f4d16a064ef75 /openstackclient/api/auth.py | |
| parent | 77097c6cd48142e94853aa568692fcae0187a885 (diff) | |
| download | python-openstackclient-fff4a1cd23057160af13f157a6fde2c172fae7a9.tar.gz | |
Add helpful messages when authN'ing with password
Setting up auth options can be complicated, and we currently don't
do any checking before we build all our auth parameters to send off
to keystoneclient. We should do some basic checking to guide new
users.
Change-Id: I9c88f1c9637b3870c151952ecc797aaf65be271a
Closes-Bug: #1400531
Diffstat (limited to 'openstackclient/api/auth.py')
| -rw-r--r-- | openstackclient/api/auth.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/openstackclient/api/auth.py b/openstackclient/api/auth.py index bfb2f83a..fa196fa4 100644 --- a/openstackclient/api/auth.py +++ b/openstackclient/api/auth.py @@ -24,6 +24,7 @@ from keystoneclient.auth import base from openstackclient.common import exceptions as exc from openstackclient.common import utils +from openstackclient.i18n import _ LOG = logging.getLogger(__name__) @@ -122,6 +123,25 @@ def build_auth_params(auth_plugin_name, cmd_options): return (auth_plugin_class, auth_params) +def check_valid_auth_options(options, auth_plugin_name): + """Perform basic option checking, provide helpful error messages""" + + msg = '' + if auth_plugin_name.endswith('password'): + if not options.os_username: + msg += _('Set a username with --os-username or OS_USERNAME\n') + if not options.os_auth_url: + msg += _('Set an authentication URL, with --os-auth-url or' + ' OS_AUTH_URL\n') + if (not options.os_project_id and not options.os_domain_id and not + options.os_domain_name and not options.os_project_name): + msg += _('Set a scope, such as a project or domain, with ' + '--os-project-name or OS_PROJECT_NAME') + + if msg: + raise exc.CommandError('Missing parameter(s): \n%s' % msg) + + def build_auth_plugins_option_parser(parser): """Auth plugins options builder @@ -140,7 +160,7 @@ def build_auth_plugins_option_parser(parser): ' (Env: OS_AUTH_TYPE)', choices=available_plugins ) - # make sur we catch old v2.0 env values + # make sure we catch old v2.0 env values envs = { 'OS_PROJECT_NAME': utils.env( 'OS_PROJECT_NAME', |
