summaryrefslogtreecommitdiff
path: root/barbicanclient
diff options
context:
space:
mode:
authorElvin Tubillara <edtubill@us.ibm.com>2015-09-17 02:30:20 -0500
committerElvin Tubillara <edtubill@us.ibm.com>2015-09-23 23:23:01 -0500
commit89c2f286a6246606335f31abf1a6289e89b427f2 (patch)
tree5f48fc018c20a1e9ded2317305a79a7bf5a58d87 /barbicanclient
parent97cc46ac2804e7679237e41a88b1183d98dac619 (diff)
downloadpython-barbicanclient-89c2f286a6246606335f31abf1a6289e89b427f2.tar.gz
enable barbican help without authentication
This fix enables 'barbican help' and 'barbican complete' to not need authentication. This commit also enables deferred_help so that the following command can be ran: 'barbican secret list --help' (the help for the particular command will be shown). The code changes are similar to the python-openstackclient usage of the cliff library. The current implementation of the barbican client authenticates before checking the type of command. This early authentication causes the client to fail with 'barbican help'. This code change will check if the command requires authentication and creates the client. Change-Id: If335ef0373c75b145dc696d8501153da59fff1b7 Closes-Bug: #1488934
Diffstat (limited to 'barbicanclient')
-rw-r--r--barbicanclient/barbican.py25
-rw-r--r--barbicanclient/tests/test_barbican.py2
2 files changed, 20 insertions, 7 deletions
diff --git a/barbicanclient/barbican.py b/barbicanclient/barbican.py
index 725e6b2..e8e49df 100644
--- a/barbicanclient/barbican.py
+++ b/barbicanclient/barbican.py
@@ -20,7 +20,10 @@ Command-line interface to the Barbican API.
import sys
from cliff import app
+from cliff import command
from cliff import commandmanager
+from cliff import complete
+from cliff import help
from keystoneclient.auth.identity import v3
from keystoneclient.auth.identity import v2
from keystoneclient import session
@@ -37,10 +40,20 @@ class Barbican(app.App):
"""Barbican command line interface."""
def __init__(self, **kwargs):
+ self.client = None
+
+ # Patch command.Command to add a default auth_required = True
+ command.Command.auth_required = True
+
+ # Some commands do not need authentication
+ help.HelpCommand.auth_required = False
+ complete.CompleteCommand.auth_required = False
+
super(Barbican, self).__init__(
description=__doc__.strip(),
version=version.__version__,
command_manager=commandmanager.CommandManager('barbican.client'),
+ deferred_help=True,
**kwargs
)
@@ -290,14 +303,14 @@ class Barbican(app.App):
session.Session.register_cli_options(parser)
return parser
- def initialize_app(self, argv):
- """Initializes the application.
- Checks if the minimal parameters are provided and creates the client
- interface.
+ def prepare_to_run_command(self, cmd):
+ """Prepares to run the command
+ Checks if the minimal parameters are provided and creates the
+ client interface.
This is inherited from the framework.
"""
- args = self.options
- self.client = self.create_client(args)
+ if cmd.auth_required:
+ self.client = self.create_client(self.options)
def run(self, argv):
# If no arguments are provided, usage is displayed
diff --git a/barbicanclient/tests/test_barbican.py b/barbicanclient/tests/test_barbican.py
index b6aa403..6b3d92c 100644
--- a/barbicanclient/tests/test_barbican.py
+++ b/barbicanclient/tests/test_barbican.py
@@ -48,7 +48,7 @@ class WhenTestingBarbicanCLI(test_client.BaseEntityResource):
return client
def test_should_show_usage_with_help_flag(self):
- e = self.assertRaises(SystemExit, self.parser.parse_known_args, ['-h'])
+ e = self.assertRaises(SystemExit, self.barbican.run, ['-h'])
self.assertEqual(0, e.code)
self.assertIn('usage', self.captured_stdout.getvalue())