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
This commit is contained in:
parent
97cc46ac28
commit
89c2f286a6
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
Loading…
Reference in New Issue