Skip to content

Commit bf582a2

Browse files
author
Doug Hellmann
committed
look at the command the user is going to run before trying to authenticate them
Change-Id: I4edc6a0f1e16be4cd80fe01f62869094b50ef120
1 parent 3b2129f commit bf582a2

2 files changed

Lines changed: 29 additions & 20 deletions

File tree

‎openstackclient/common/clientmanager.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ def __init__(self, token=None, url=None,
7171
self._image_api_version = image_api_version
7272
self._service_catalog = None
7373

74-
# Create the identity client
75-
self.identity
76-
7774
if not self._url:
7875
# Populate other password flow attributes
7976
self._token = self.identity.auth_token

‎openstackclient/shell.py‎

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,10 @@ def build_option_parser(self, description, version):
124124

125125
return parser
126126

127-
def initialize_app(self):
128-
"""Global app init bits:
129-
130-
* set up API versions
131-
* validate authentication info
132-
* authenticate against Identity if requested
127+
def authenticate_user(self):
128+
"""Make sure the user has provided all of the authentication
129+
info we need.
133130
"""
134-
135-
super(OpenStackShell, self).initialize_app()
136-
137-
# stash selected API versions for later
138-
# TODO(dtroyer): how do extenstions add their version requirements?
139-
self.api_version = {
140-
'compute': self.options.os_compute_api_version,
141-
'identity': self.options.os_identity_api_version,
142-
'image': self.options.os_image_api_version,
143-
}
144-
145131
self.log.debug('validating authentication options')
146132
if self.options.os_token or self.options.os_url:
147133
# Token flow auth takes priority
@@ -190,6 +176,32 @@ def initialize_app(self):
190176
compute_api_version=self.options.os_compute_api_version,
191177
image_api_version=self.options.os_image_api_version,
192178
)
179+
return
180+
181+
def initialize_app(self, argv):
182+
"""Global app init bits:
183+
184+
* set up API versions
185+
* validate authentication info
186+
* authenticate against Identity if requested
187+
"""
188+
189+
super(OpenStackShell, self).initialize_app(argv)
190+
191+
# stash selected API versions for later
192+
# TODO(dtroyer): how do extenstions add their version requirements?
193+
self.api_version = {
194+
'compute': self.options.os_compute_api_version,
195+
'identity': self.options.os_identity_api_version,
196+
'image': self.options.os_image_api_version,
197+
}
198+
199+
# If the user is not asking for help, make sure they
200+
# have given us auth.
201+
cmd_info = self.command_manager.find_command(argv)
202+
cmd_factory, cmd_name, sub_argv = cmd_info
203+
if cmd_name != 'help':
204+
self.authenticate_user()
193205

194206
self.log.debug("API: Identity=%s Compute=%s Image=%s" % (
195207
self.api_version['identity'],

0 commit comments

Comments
 (0)