From 14dbfe44741b65c9e0514a34669f52de8629b1c0 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Thu, 1 Sep 2016 10:54:29 -0500 Subject: Defer auth prompting until it is actually needed Auth option prompting happens waaaay to early in the default os-client-config flow, we need to defer it until adter the commands have been parsed. This is why ClientManager.setup_auth() exists, as it is not called until the first attempt to connect to a server occurs. Commands that do not require authentication never hit this. Also, required options were not being enforced. By doing this we handle when no authentication info is present, we fail on missing auth-url rather than attempt to prompt for a password (default auth is password). Closes-Bug: 1619274 Change-Id: Ia4eae350e6904c9eb2c8507d9b3429fe52418726 --- openstackclient/common/clientmanager.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'openstackclient/common/clientmanager.py') diff --git a/openstackclient/common/clientmanager.py b/openstackclient/common/clientmanager.py index 57423aed..23c35a3b 100644 --- a/openstackclient/common/clientmanager.py +++ b/openstackclient/common/clientmanager.py @@ -60,6 +60,26 @@ class ClientManager(clientmanager.ClientManager): self._cacert = self.cacert self._insecure = not self.verify + def setup_auth(self): + """Set up authentication""" + + if self._auth_setup_completed: + return + + # NOTE(dtroyer): Validate the auth args; this is protected with 'if' + # because openstack_config is an optional argument to + # CloudConfig.__init__() and we'll die if it was not + # passed. + if self._cli_options._openstack_config is not None: + self._cli_options._openstack_config._pw_callback = \ + shell.prompt_for_password + self._cli_options._auth = \ + self._cli_options._openstack_config.load_auth_plugin( + self._cli_options.config, + ) + + return super(ClientManager, self).setup_auth() + def is_network_endpoint_enabled(self): """Check if the network endpoint is enabled""" -- cgit v1.2.1