diff --git a/.gitreview b/.gitreview index 6cf44857..a0f15f06 100644 --- a/.gitreview +++ b/.gitreview @@ -2,3 +2,4 @@ host=review.opendev.org port=29418 project=openstack/python-swiftclient.git +defaultbranch=stable/2025.1 diff --git a/swiftclient/shell.py b/swiftclient/shell.py index 1dc8d2f4..23691f25 100755 --- a/swiftclient/shell.py +++ b/swiftclient/shell.py @@ -1638,14 +1638,17 @@ def prompt_for_password(): def parse_args(parser, args, enforce_requires=True): options, args = parser.parse_known_args(args or ['-h']) options = vars(options) - if enforce_requires and (options.get('debug') or options.get('info')): + if enforce_requires and (options.get('debug') or + options.get('debug_with_secrets') or + options.get('info')): logging.getLogger("swiftclient") - if options.get('debug'): + if options.get('debug') or options.get('debug_with_secrets'): logging.basicConfig(level=logging.DEBUG) logging.getLogger('iso8601').setLevel(logging.WARNING) - client_logger_settings['redact_sensitive_headers'] = False elif options.get('info'): logging.basicConfig(level=logging.INFO) + client_logger_settings['redact_sensitive_headers'] = not ( + enforce_requires and options.get('debug_with_secrets')) if args and options.get('help'): _help = globals().get('st_%s_help' % args[0]) @@ -1732,6 +1735,11 @@ def add_default_args(parser): default=False, help='Show the curl commands and ' 'results of all http queries regardless of result ' 'status.') + parser.add_argument('--debug-with-secrets', action='store_true', + dest='debug_with_secrets', default=False, + help='Show the curl commands and ' + 'results of all http queries regardless of result ' + 'status (without truncating auth tokens).') parser.add_argument('--info', action='store_true', dest='info', default=False, help='Show the curl commands and ' 'results of all http queries which return an error.') @@ -1958,8 +1966,8 @@ def main(arguments=None): parser = argparse.ArgumentParser( add_help=False, formatter_class=HelpFormatter, usage=''' %(prog)s [--version] [--help] [--os-help] [--snet] [--verbose] - [--debug] [--info] [--quiet] [--auth ] - [--auth-version | + [--debug] [--debug-with-secrets] [--info] [--quiet] + [--auth ] [--auth-version | --os-identity-api-version ] [--user ] [--key ] [--retries ] diff --git a/test/unit/test_shell.py b/test/unit/test_shell.py index e4e19012..b2b34431 100644 --- a/test/unit/test_shell.py +++ b/test/unit/test_shell.py @@ -2647,10 +2647,23 @@ def test_option_after_posarg(self, connection, mock_logging): argv = ["", "stat", "--info"] swiftclient.shell.main(argv) mock_logging.assert_called_with(level=logging.INFO) + self.assertTrue( + swiftclient.logger_settings.get('redact_sensitive_headers') + ) argv = ["", "stat", "--debug"] swiftclient.shell.main(argv) mock_logging.assert_called_with(level=logging.DEBUG) + self.assertTrue( + swiftclient.logger_settings.get('redact_sensitive_headers') + ) + + argv = ["", "stat", "--debug-with-secrets"] + swiftclient.shell.main(argv) + mock_logging.assert_called_with(level=logging.DEBUG) + self.assertFalse( + swiftclient.logger_settings.get('redact_sensitive_headers') + ) @mock.patch('logging.basicConfig') @mock.patch('swiftclient.service.Connection') @@ -2660,7 +2673,13 @@ def test_debug_trumps_info(self, connection, mock_logging): ["", "--info", "stat", "--debug"], ["", "--debug", "stat", "--info"], ["", "--info", "--debug", "stat"], - ["", "--debug", "--info", "stat"]) + ["", "--debug", "--info", "stat"], + ["", "stat", "--info", "--debug-with-secrets"], + ["", "stat", "--debug-with-secrets", "--info"], + ["", "--info", "stat", "--debug-with-secrets"], + ["", "--debug-with-secrets", "stat", "--info"], + ["", "--info", "--debug-with-secrets", "stat"], + ["", "--debug-with-secrets", "--info", "stat"]) for argv in argv_scenarios: mock_logging.reset_mock() swiftclient.shell.main(argv) diff --git a/tox.ini b/tox.ini index 097a9949..ce9cb64d 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,7 @@ setenv = LANG=en_US.utf-8 VIRTUAL_ENV={envdir} -deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} +deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2025.1} -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt commands = sh -c '(find . -not \( -type d -name .?\* -prune \) \ @@ -60,7 +60,7 @@ commands = [testenv:docs] usedevelop = False -deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} +deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2025.1} -r{toxinidir}/doc/requirements.txt commands= sphinx-build -W -b html doc/source doc/build/html -W