Redact auth from URL in UpdatingDefaultsHelpFormatter

This commit is contained in:
Noah Gorny 2020-11-25 21:16:41 +02:00
parent 84382715f0
commit 8f821866d6
2 changed files with 13 additions and 1 deletions

1
news/9160.bugfix.rst Normal file
View File

@ -0,0 +1 @@
Redact auth from URL in help message.

View File

@ -17,6 +17,7 @@ from pip._vendor.six import string_types
from pip._internal.cli.status_codes import UNKNOWN_ERROR
from pip._internal.configuration import Configuration, ConfigurationError
from pip._internal.utils.compat import get_terminal_size
from pip._internal.utils.misc import redact_auth_from_url
logger = logging.getLogger(__name__)
@ -106,12 +107,22 @@ class UpdatingDefaultsHelpFormatter(PrettyHelpFormatter):
This is updates the defaults before expanding them, allowing
them to show up correctly in the help listing.
Also redact auth from url type options
"""
def expand_default(self, option):
default_value = None
if self.parser is not None:
self.parser._update_defaults(self.parser.defaults)
return optparse.IndentedHelpFormatter.expand_default(self, option)
default_value = self.parser.defaults.get(option.dest)
help_text = optparse.IndentedHelpFormatter.expand_default(self, option)
if default_value and option.metavar == 'URL':
help_text = help_text.replace(
default_value, redact_auth_from_url(default_value))
return help_text
class CustomOptionParser(optparse.OptionParser):