diff --git a/certbot-nginx/certbot_nginx/configurator.py b/certbot-nginx/certbot_nginx/configurator.py index ec657a9db..fbe881bb0 100644 --- a/certbot-nginx/certbot_nginx/configurator.py +++ b/certbot-nginx/certbot_nginx/configurator.py @@ -87,8 +87,6 @@ class NginxConfigurator(common.Plugin): description = "Nginx Web Server plugin - Alpha" - hidden = True - DEFAULT_LISTEN_PORT = '80' @classmethod diff --git a/certbot/plugins/selection.py b/certbot/plugins/selection.py index fdfbf2b15..9e2ddf609 100644 --- a/certbot/plugins/selection.py +++ b/certbot/plugins/selection.py @@ -108,11 +108,19 @@ def choose_plugin(prepared, question): opts = [plugin_ep.description_with_name + (" [Misconfigured]" if plugin_ep.misconfigured else "") for plugin_ep in prepared] + names = set(plugin_ep.name for plugin_ep in prepared) while True: disp = z_util(interfaces.IDisplay) - code, index = disp.menu( - question, opts, force_interactive=True) + if "CERTBOT_AUTO" in os.environ and names == set(("apache", "nginx")): + # The possibility of being offered exactly apache and nginx here + # is new interactivity brought by https://github.com/certbot/certbot/issues/4079, + # so set apache as a default for those kinds of non-interactive use + # (the user will get a warning to set --non-interactive or --force-interactive) + apache_idx = [n for n, p in enumerate(prepared) if p.name == "apache"][0] + code, index = disp.menu(question, opts, default=apache_idx) + else: + code, index = disp.menu(question, opts, force_interactive=True) if code == display_util.OK: plugin_ep = prepared[index] diff --git a/certbot/plugins/selection_test.py b/certbot/plugins/selection_test.py index 9f0716905..4112810a2 100644 --- a/certbot/plugins/selection_test.py +++ b/certbot/plugins/selection_test.py @@ -1,4 +1,5 @@ """Tests for letsencrypt.plugins.selection""" +import os import sys import unittest @@ -115,6 +116,7 @@ class ChoosePluginTest(unittest.TestCase): False)) self.mock_apache = mock.Mock( description_with_name="a", misconfigured=True) + self.mock_apache.name = "apache" self.mock_stand = mock.Mock( description_with_name="s", misconfigured=False) self.mock_stand.init().more_info.return_value = "standalone" @@ -146,3 +148,26 @@ class ChoosePluginTest(unittest.TestCase): def test_no_choice(self, mock_util): mock_util().menu.return_value = (display_util.CANCEL, 0) self.assertTrue(self._call() is None) + + @test_util.patch_get_utility("certbot.plugins.selection.z_util") + def test_new_interaction_avoidance(self, mock_util): + mock_nginx = mock.Mock( + description_with_name="n", misconfigured=False) + mock_nginx.init().more_info.return_value = "nginx plugin" + mock_nginx.name = "nginx" + self.plugins[1] = mock_nginx + mock_util().menu.return_value = (display_util.CANCEL, 0) + + unset_cb_auto = os.environ.get("CERTBOT_AUTO") is None + if unset_cb_auto: + os.environ["CERTBOT_AUTO"] = "foo" + try: + self._call() + finally: + if unset_cb_auto: + del os.environ["CERTBOT_AUTO"] + + self.assertTrue("default" in mock_util().menu.call_args[1]) + +if __name__ == "__main__": + unittest.main() # pragma: no cover