mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 19:14:54 +02:00
Low-impact cleanup of IDisplay (#4818)
Remove unused help-related display code. When NcursesDisplay was
removed[1], help was deprecated. This change removes the remaining
bits and pieces of code.
Remove unused escape-related display code. When NcursesDisplay was
removed[1], escape was deprecated. This change removes the remaining
bits and pieces of code.
Remove uses of unused menu parameters.
Remove unused default_status/default_state argument from checklist.
(This seems safe because not only is it unused, the parameter has
different names in the interface and implementation)
1 - d54cb76432
Resolves #4795.
This commit is contained in:
committed by
Brad Warren
parent
0a269f31d0
commit
f51d345d5b
@@ -27,9 +27,7 @@ def select_vhost(domain, vhosts):
|
|||||||
return None
|
return None
|
||||||
while True:
|
while True:
|
||||||
code, tag = _vhost_menu(domain, vhosts)
|
code, tag = _vhost_menu(domain, vhosts)
|
||||||
if code == display_util.HELP:
|
if code == display_util.OK:
|
||||||
_more_info_vhost(vhosts[tag])
|
|
||||||
elif code == display_util.OK:
|
|
||||||
return vhosts[tag]
|
return vhosts[tag]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
@@ -85,8 +83,7 @@ def _vhost_menu(domain, vhosts):
|
|||||||
"or Address of {0}.{1}Which virtual host would you "
|
"or Address of {0}.{1}Which virtual host would you "
|
||||||
"like to choose?\n(note: conf files with multiple "
|
"like to choose?\n(note: conf files with multiple "
|
||||||
"vhosts are not yet supported)".format(domain, os.linesep),
|
"vhosts are not yet supported)".format(domain, os.linesep),
|
||||||
choices, help_label="More Info",
|
choices, force_interactive=True)
|
||||||
ok_label="Select", force_interactive=True)
|
|
||||||
except errors.MissingCommandlineFlag:
|
except errors.MissingCommandlineFlag:
|
||||||
msg = ("Encountered vhost ambiguity but unable to ask for user guidance in "
|
msg = ("Encountered vhost ambiguity but unable to ask for user guidance in "
|
||||||
"non-interactive mode. Currently Certbot needs each vhost to be "
|
"non-interactive mode. Currently Certbot needs each vhost to be "
|
||||||
@@ -96,10 +93,3 @@ def _vhost_menu(domain, vhosts):
|
|||||||
raise errors.MissingCommandlineFlag(msg)
|
raise errors.MissingCommandlineFlag(msg)
|
||||||
|
|
||||||
return code, tag
|
return code, tag
|
||||||
|
|
||||||
|
|
||||||
def _more_info_vhost(vhost):
|
|
||||||
zope.component.getUtility(interfaces.IDisplay).notification(
|
|
||||||
"Virtual Host Information:{0}{1}{0}{2}".format(
|
|
||||||
os.linesep, "-" * (display_util.WIDTH - 4), str(vhost)),
|
|
||||||
force_interactive=True)
|
|
||||||
|
|||||||
@@ -43,13 +43,10 @@ class SelectVhostTest(unittest.TestCase):
|
|||||||
@certbot_util.patch_get_utility()
|
@certbot_util.patch_get_utility()
|
||||||
def test_more_info_cancel(self, mock_util):
|
def test_more_info_cancel(self, mock_util):
|
||||||
mock_util().menu.side_effect = [
|
mock_util().menu.side_effect = [
|
||||||
(display_util.HELP, 1),
|
|
||||||
(display_util.HELP, 0),
|
|
||||||
(display_util.CANCEL, -1),
|
(display_util.CANCEL, -1),
|
||||||
]
|
]
|
||||||
|
|
||||||
self.assertEqual(None, self._call(self.vhosts))
|
self.assertEqual(None, self._call(self.vhosts))
|
||||||
self.assertEqual(mock_util().notification.call_count, 2)
|
|
||||||
|
|
||||||
def test_no_vhosts(self):
|
def test_no_vhosts(self):
|
||||||
self.assertEqual(self._call([]), None)
|
self.assertEqual(self._call([]), None)
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ def _get_certname(config, verb):
|
|||||||
if not choices:
|
if not choices:
|
||||||
raise errors.Error("No existing certificates found.")
|
raise errors.Error("No existing certificates found.")
|
||||||
code, index = disp.menu("Which certificate would you like to {0}?".format(verb),
|
code, index = disp.menu("Which certificate would you like to {0}?".format(verb),
|
||||||
choices, ok_label="Select", flag="--cert-name",
|
choices, flag="--cert-name",
|
||||||
force_interactive=True)
|
force_interactive=True)
|
||||||
if code != display_util.OK or not index in range(0, len(choices)):
|
if code != display_util.OK or not index in range(0, len(choices)):
|
||||||
raise errors.Error("User ended interaction.")
|
raise errors.Error("User ended interaction.")
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ CANCEL = "cancel"
|
|||||||
"""Display exit code for a user canceling the display."""
|
"""Display exit code for a user canceling the display."""
|
||||||
|
|
||||||
HELP = "help"
|
HELP = "help"
|
||||||
"""Display exit code when for when the user requests more help."""
|
"""Display exit code when for when the user requests more help. (UNUSED)"""
|
||||||
|
|
||||||
ESC = "esc"
|
ESC = "esc"
|
||||||
"""Display exit code when the user hits Escape"""
|
"""Display exit code when the user hits Escape (UNUSED)"""
|
||||||
|
|
||||||
|
|
||||||
def _wrap_lines(msg):
|
def _wrap_lines(msg):
|
||||||
@@ -123,8 +123,8 @@ class FileDisplay(object):
|
|||||||
else:
|
else:
|
||||||
logger.debug("Not pausing for user confirmation")
|
logger.debug("Not pausing for user confirmation")
|
||||||
|
|
||||||
def menu(self, message, choices, ok_label="", cancel_label="",
|
def menu(self, message, choices, ok_label=None, cancel_label=None,
|
||||||
help_label="", default=None,
|
help_label=None, default=None,
|
||||||
cli_flag=None, force_interactive=False, **unused_kwargs):
|
cli_flag=None, force_interactive=False, **unused_kwargs):
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
"""Display a menu.
|
"""Display a menu.
|
||||||
@@ -228,14 +228,13 @@ class FileDisplay(object):
|
|||||||
ans.startswith(no_label[0].upper())):
|
ans.startswith(no_label[0].upper())):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def checklist(self, message, tags, default_status=True, default=None,
|
def checklist(self, message, tags, default=None,
|
||||||
cli_flag=None, force_interactive=False, **unused_kwargs):
|
cli_flag=None, force_interactive=False, **unused_kwargs):
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
"""Display a checklist.
|
"""Display a checklist.
|
||||||
|
|
||||||
:param str message: Message to display to user
|
:param str message: Message to display to user
|
||||||
:param list tags: `str` tags to select, len(tags) > 0
|
:param list tags: `str` tags to select, len(tags) > 0
|
||||||
:param bool default_status: Not used for FileDisplay
|
|
||||||
:param default: default value to return (if one exists)
|
:param default: default value to return (if one exists)
|
||||||
:param str cli_flag: option used to set this value with the CLI
|
:param str cli_flag: option used to set this value with the CLI
|
||||||
:param bool force_interactive: True if it's safe to prompt the user
|
:param bool force_interactive: True if it's safe to prompt the user
|
||||||
|
|||||||
@@ -396,8 +396,8 @@ class IDisplay(zope.interface.Interface):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def menu(message, choices, ok_label="OK",
|
def menu(message, choices, ok_label=None,
|
||||||
cancel_label="Cancel", help_label="",
|
cancel_label=None, help_label=None,
|
||||||
default=None, cli_flag=None, force_interactive=False):
|
default=None, cli_flag=None, force_interactive=False):
|
||||||
"""Displays a generic menu.
|
"""Displays a generic menu.
|
||||||
|
|
||||||
@@ -409,9 +409,9 @@ class IDisplay(zope.interface.Interface):
|
|||||||
:param choices: choices
|
:param choices: choices
|
||||||
:type choices: :class:`list` of :func:`tuple` or :class:`str`
|
:type choices: :class:`list` of :func:`tuple` or :class:`str`
|
||||||
|
|
||||||
:param str ok_label: label for OK button
|
:param str ok_label: label for OK button (UNUSED)
|
||||||
:param str cancel_label: label for Cancel button
|
:param str cancel_label: label for Cancel button (UNUSED)
|
||||||
:param str help_label: label for Help button
|
:param str help_label: label for Help button (UNUSED)
|
||||||
:param int default: default (non-interactive) choice from the menu
|
:param int default: default (non-interactive) choice from the menu
|
||||||
:param str cli_flag: to automate choice from the menu, eg "--keep"
|
:param str cli_flag: to automate choice from the menu, eg "--keep"
|
||||||
:param bool force_interactive: True if it's safe to prompt the user
|
:param bool force_interactive: True if it's safe to prompt the user
|
||||||
@@ -470,8 +470,7 @@ class IDisplay(zope.interface.Interface):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def checklist(message, tags, default_state,
|
def checklist(message, tags, default=None, cli_args=None, force_interactive=False):
|
||||||
default=None, cli_args=None, force_interactive=False):
|
|
||||||
"""Allow for multiple selections from a menu.
|
"""Allow for multiple selections from a menu.
|
||||||
|
|
||||||
When not setting force_interactive=True, you must provide a
|
When not setting force_interactive=True, you must provide a
|
||||||
@@ -479,7 +478,6 @@ class IDisplay(zope.interface.Interface):
|
|||||||
|
|
||||||
:param str message: message to display to the user
|
:param str message: message to display to the user
|
||||||
:param list tags: where each is of type :class:`str` len(tags) > 0
|
:param list tags: where each is of type :class:`str` len(tags) > 0
|
||||||
:param bool default_status: If True, items are in a selected state by default.
|
|
||||||
:param str default: default (non-interactive) state of the checklist
|
:param str default: default (non-interactive) state of the checklist
|
||||||
:param str cli_flag: to automate choice from the menu, eg "--domains"
|
:param str cli_flag: to automate choice from the menu, eg "--domains"
|
||||||
:param bool force_interactive: True if it's safe to prompt the user
|
:param bool force_interactive: True if it's safe to prompt the user
|
||||||
|
|||||||
+1
-1
@@ -161,7 +161,7 @@ def _handle_identical_cert_request(config, lineage):
|
|||||||
"Renew & replace the cert (limit ~5 per 7 days)"]
|
"Renew & replace the cert (limit ~5 per 7 days)"]
|
||||||
|
|
||||||
display = zope.component.getUtility(interfaces.IDisplay)
|
display = zope.component.getUtility(interfaces.IDisplay)
|
||||||
response = display.menu(question, choices, "OK", "Cancel",
|
response = display.menu(question, choices,
|
||||||
default=0, force_interactive=True)
|
default=0, force_interactive=True)
|
||||||
if response[0] == display_util.CANCEL:
|
if response[0] == display_util.CANCEL:
|
||||||
# TODO: Add notification related to command-line options for
|
# TODO: Add notification related to command-line options for
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ def choose_plugin(prepared, question):
|
|||||||
while True:
|
while True:
|
||||||
disp = z_util(interfaces.IDisplay)
|
disp = z_util(interfaces.IDisplay)
|
||||||
code, index = disp.menu(
|
code, index = disp.menu(
|
||||||
question, opts, help_label="More Info", force_interactive=True)
|
question, opts, force_interactive=True)
|
||||||
|
|
||||||
if code == display_util.OK:
|
if code == display_util.OK:
|
||||||
plugin_ep = prepared[index]
|
plugin_ep = prepared[index]
|
||||||
@@ -123,13 +123,6 @@ def choose_plugin(prepared, question):
|
|||||||
"was:\n\n{0}".format(plugin_ep.prepare()), pause=False)
|
"was:\n\n{0}".format(plugin_ep.prepare()), pause=False)
|
||||||
else:
|
else:
|
||||||
return plugin_ep
|
return plugin_ep
|
||||||
elif code == display_util.HELP:
|
|
||||||
if prepared[index].misconfigured:
|
|
||||||
msg = "Reported Error: %s" % prepared[index].prepare()
|
|
||||||
else:
|
|
||||||
msg = prepared[index].init().more_info()
|
|
||||||
z_util(interfaces.IDisplay).notification(msg,
|
|
||||||
force_interactive=True)
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -137,13 +137,10 @@ class ChoosePluginTest(unittest.TestCase):
|
|||||||
@test_util.patch_get_utility("certbot.plugins.selection.z_util")
|
@test_util.patch_get_utility("certbot.plugins.selection.z_util")
|
||||||
def test_more_info(self, mock_util):
|
def test_more_info(self, mock_util):
|
||||||
mock_util().menu.side_effect = [
|
mock_util().menu.side_effect = [
|
||||||
(display_util.HELP, 0),
|
|
||||||
(display_util.HELP, 1),
|
|
||||||
(display_util.OK, 1),
|
(display_util.OK, 1),
|
||||||
]
|
]
|
||||||
|
|
||||||
self.assertEqual(self.mock_stand, self._call())
|
self.assertEqual(self.mock_stand, self._call())
|
||||||
self.assertEqual(mock_util().notification.call_count, 2)
|
|
||||||
|
|
||||||
@test_util.patch_get_utility("certbot.plugins.selection.z_util")
|
@test_util.patch_get_utility("certbot.plugins.selection.z_util")
|
||||||
def test_no_choice(self, mock_util):
|
def test_no_choice(self, mock_util):
|
||||||
|
|||||||
@@ -117,22 +117,11 @@ to serve all files under specified web root ({0})."""
|
|||||||
code, index = display.menu(
|
code, index = display.menu(
|
||||||
"Select the webroot for {0}:".format(domain),
|
"Select the webroot for {0}:".format(domain),
|
||||||
["Enter a new webroot"] + known_webroots,
|
["Enter a new webroot"] + known_webroots,
|
||||||
help_label="Help", cli_flag=path_flag, force_interactive=True)
|
cli_flag=path_flag, force_interactive=True)
|
||||||
if code == display_util.CANCEL:
|
if code == display_util.CANCEL:
|
||||||
raise errors.PluginError(
|
raise errors.PluginError(
|
||||||
"Every requested domain must have a "
|
"Every requested domain must have a "
|
||||||
"webroot when using the webroot plugin.")
|
"webroot when using the webroot plugin.")
|
||||||
elif code == display_util.HELP:
|
|
||||||
display.notification(
|
|
||||||
"To use the webroot plugin, you need to have an "
|
|
||||||
"HTTP server running on this system serving files "
|
|
||||||
"for the requested domain. Additionally, this "
|
|
||||||
"server should be serving all files contained in a "
|
|
||||||
"public_html or webroot directory. The webroot "
|
|
||||||
"plugin works by temporarily saving necessary "
|
|
||||||
"resources in the HTTP server's webroot directory "
|
|
||||||
"to pass domain validation challenges.",
|
|
||||||
force_interactive=True)
|
|
||||||
else: # code == display_util.OK
|
else: # code == display_util.OK
|
||||||
return None if index == 0 else known_webroots[index - 1]
|
return None if index == 0 else known_webroots[index - 1]
|
||||||
|
|
||||||
@@ -141,10 +130,7 @@ to serve all files under specified web root ({0})."""
|
|||||||
_validate_webroot,
|
_validate_webroot,
|
||||||
"Input the webroot for {0}:".format(domain),
|
"Input the webroot for {0}:".format(domain),
|
||||||
force_interactive=True)
|
force_interactive=True)
|
||||||
if code == display_util.HELP:
|
if code == display_util.CANCEL:
|
||||||
# Displaying help is not currently implemented
|
|
||||||
return None
|
|
||||||
elif code == display_util.CANCEL or code == display_util.ESC:
|
|
||||||
return None
|
return None
|
||||||
else: # code == display_util.OK
|
else: # code == display_util.OK
|
||||||
return _validate_webroot(webroot)
|
return _validate_webroot(webroot)
|
||||||
|
|||||||
@@ -84,10 +84,8 @@ class AuthenticatorTest(unittest.TestCase):
|
|||||||
self.config.webroot_map = {"otherthing.com": self.path}
|
self.config.webroot_map = {"otherthing.com": self.path}
|
||||||
|
|
||||||
mock_display = mock_get_utility()
|
mock_display = mock_get_utility()
|
||||||
mock_display.menu.side_effect = ((display_util.HELP, -1),
|
mock_display.menu.side_effect = ((display_util.CANCEL, -1),)
|
||||||
(display_util.CANCEL, -1),)
|
|
||||||
self.assertRaises(errors.PluginError, self.auth.perform, [self.achall])
|
self.assertRaises(errors.PluginError, self.auth.perform, [self.achall])
|
||||||
self.assertTrue(mock_display.notification.called)
|
|
||||||
self.assertTrue(mock_display.menu.called)
|
self.assertTrue(mock_display.menu.called)
|
||||||
for call in mock_display.menu.call_args_list:
|
for call in mock_display.menu.call_args_list:
|
||||||
self.assertTrue(self.achall.domain in call[0][0])
|
self.assertTrue(self.achall.domain in call[0][0])
|
||||||
@@ -103,8 +101,7 @@ class AuthenticatorTest(unittest.TestCase):
|
|||||||
mock_display = mock_get_utility()
|
mock_display = mock_get_utility()
|
||||||
mock_display.menu.return_value = (display_util.OK, 0,)
|
mock_display.menu.return_value = (display_util.OK, 0,)
|
||||||
with mock.patch('certbot.display.ops.validated_directory') as m:
|
with mock.patch('certbot.display.ops.validated_directory') as m:
|
||||||
m.side_effect = ((display_util.HELP, -1),
|
m.side_effect = ((display_util.CANCEL, -1),
|
||||||
(display_util.CANCEL, -1),
|
|
||||||
(display_util.OK, self.path,))
|
(display_util.OK, self.path,))
|
||||||
|
|
||||||
self.auth.perform([self.achall])
|
self.auth.perform([self.achall])
|
||||||
|
|||||||
Reference in New Issue
Block a user