Make bash comple command best effort to authorize
If authorization fails for the complete command, generate the bash complete anyway. * Added best_effort flag to command * Attempts to authorize for bash complete, but if it fails, it tries anyway Change-Id: I796258f8044f42abc6a51164d920a26f73397962 Partial-Bug: #1283550
This commit is contained in:
		| @@ -24,6 +24,7 @@ import traceback | ||||
|  | ||||
| from cliff import app | ||||
| from cliff import command | ||||
| from cliff import complete | ||||
| from cliff import help | ||||
|  | ||||
| import openstackclient | ||||
| @@ -64,8 +65,10 @@ class OpenStackShell(app.App): | ||||
|     def __init__(self): | ||||
|         # Patch command.Command to add a default auth_required = True | ||||
|         command.Command.auth_required = True | ||||
|         command.Command.best_effort = False | ||||
|         # But not help | ||||
|         help.HelpCommand.auth_required = False | ||||
|         complete.CompleteCommand.best_effort = True | ||||
|  | ||||
|         super(OpenStackShell, self).__init__( | ||||
|             description=__doc__.strip(), | ||||
| @@ -465,7 +468,15 @@ class OpenStackShell(app.App): | ||||
|         """Set up auth and API versions""" | ||||
|         self.log.debug('prepare_to_run_command %s', cmd.__class__.__name__) | ||||
|  | ||||
|         if cmd.auth_required: | ||||
|         if not cmd.auth_required: | ||||
|             return | ||||
|         if cmd.best_effort: | ||||
|             try: | ||||
|                 self.authenticate_user() | ||||
|                 self.restapi.set_auth(self.client_manager.identity.auth_token) | ||||
|             except Exception: | ||||
|                 pass | ||||
|         else: | ||||
|             self.authenticate_user() | ||||
|             self.restapi.set_auth(self.client_manager.identity.auth_token) | ||||
|         return | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Terry Howe
					Terry Howe