mirror of
https://github.com/certbot/certbot.git
synced 2026-06-13 10:40:10 -04:00
Refactored the runners
This commit is contained in:
parent
99d8bfadf7
commit
4c5635cca3
6 changed files with 82 additions and 74 deletions
|
|
@ -225,7 +225,7 @@ single-line-if-stmt=no
|
|||
no-space-check=trailing-comma
|
||||
|
||||
# Maximum number of lines in a module
|
||||
max-module-lines=1300
|
||||
max-module-lines=1250
|
||||
|
||||
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
|
||||
# tab).
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ from certbot import log
|
|||
from certbot import renewal
|
||||
from certbot import reporter
|
||||
from certbot import storage
|
||||
from certbot import updater
|
||||
from certbot import util
|
||||
|
||||
from certbot.display import util as display_util, ops as display_ops
|
||||
|
|
@ -1075,67 +1076,7 @@ def renew_cert(config, plugins, lineage):
|
|||
notify("new certificate deployed with reload of {0} server; fullchain is {1}".format(
|
||||
config.installer, lineage.fullchain), pause=False)
|
||||
# Run deployer
|
||||
_run_renewal_deployer(renewed_lineage, installer, config)
|
||||
|
||||
def run_renewal_updaters(config, plugins, lineage):
|
||||
"""Run updaters that the plugin supports
|
||||
|
||||
:param config: Configuration object
|
||||
:type config: interfaces.IConfig
|
||||
|
||||
:param plugins: List of plugins
|
||||
:type plugins: `list` of `str`
|
||||
|
||||
:param lineage: Certificate lineage object
|
||||
:type lineage: storage.RenewableCert
|
||||
|
||||
:returns: `None`
|
||||
:rtype: None
|
||||
"""
|
||||
try:
|
||||
# installers are used in auth mode to determine domain names
|
||||
installer, _ = plug_sel.choose_configurator_plugins(config, plugins, "certonly")
|
||||
except errors.PluginSelectionError as e:
|
||||
logger.info("Could not choose appropriate plugin: %s", e)
|
||||
raise
|
||||
_run_updaters(lineage, installer, config)
|
||||
|
||||
def _run_renewal_deployer(lineage, installer, config):
|
||||
"""Helper function to run deployer interface method if supported by the used
|
||||
installer plugin.
|
||||
|
||||
:param lineage: Certificate lineage object
|
||||
:type lineage: storage.RenewableCert
|
||||
|
||||
:param installer: Installer object
|
||||
:type installer: interfaces.IInstaller
|
||||
|
||||
:returns: `None`
|
||||
:rtype: None
|
||||
"""
|
||||
if config.installer_updates and isinstance(installer, interfaces.RenewDeployer):
|
||||
installer.renew_deploy(lineage)
|
||||
|
||||
def _run_updaters(lineage, installer, config):
|
||||
"""Helper function to run the updater interface methods if supported by the
|
||||
used installer plugin.
|
||||
|
||||
:param lineage: Certificate lineage object
|
||||
:type lineage: storage.RenewableCert
|
||||
|
||||
:param installer: Installer object
|
||||
:type installer: interfaces.IInstaller
|
||||
|
||||
:returns: `None`
|
||||
:rtype: None
|
||||
"""
|
||||
for domain in lineage.names():
|
||||
if config.server_tls_updates:
|
||||
if isinstance(installer, interfaces.ServerTLSUpdater):
|
||||
installer.server_tls_updates(domain)
|
||||
if config.installer_updates:
|
||||
if isinstance(installer, interfaces.GenericUpdater):
|
||||
installer.generic_updates(domain)
|
||||
updater.run_renewal_deployer(renewed_lineage, installer, config)
|
||||
|
||||
def certonly(config, plugins):
|
||||
"""Authenticate & obtain cert, but do not install it.
|
||||
|
|
|
|||
|
|
@ -12,13 +12,14 @@ import zope.component
|
|||
import OpenSSL
|
||||
|
||||
from certbot import cli
|
||||
|
||||
from certbot import crypto_util
|
||||
from certbot import errors
|
||||
from certbot import interfaces
|
||||
from certbot import util
|
||||
from certbot import hooks
|
||||
from certbot import storage
|
||||
from certbot import updater
|
||||
|
||||
from certbot.plugins import disco as plugins_disco
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -427,7 +428,8 @@ def handle_renewal_request(config):
|
|||
else:
|
||||
renew_skipped.append(renewal_candidate.fullchain)
|
||||
# Run updater interface methods
|
||||
main.run_renewal_updaters(lineage_config, plugins, renewal_candidate)
|
||||
updater.run_renewal_updaters(lineage_config, plugins,
|
||||
renewal_candidate)
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
# obtain_cert (presumably) encountered an unanticipated problem.
|
||||
logger.warning("Attempting to renew cert (%s) from %s produced an "
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from certbot import configuration
|
|||
from certbot import crypto_util
|
||||
from certbot import errors
|
||||
from certbot import main
|
||||
from certbot import updater
|
||||
from certbot import util
|
||||
|
||||
from certbot.plugins import disco
|
||||
|
|
@ -1373,7 +1374,7 @@ class MainTest(test_util.ConfigTestCase): # pylint: disable=too-many-public-met
|
|||
mock_choose.side_effect = errors.PluginSelectionError
|
||||
self.assertRaises(errors.PluginSelectionError, main.renew_cert,
|
||||
None, None, None)
|
||||
self.assertRaises(errors.PluginSelectionError, main.run_renewal_updaters,
|
||||
self.assertRaises(errors.PluginSelectionError, updater.run_renewal_updaters,
|
||||
None, None, None)
|
||||
|
||||
class UnregisterTest(unittest.TestCase):
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import mock
|
|||
from certbot import errors
|
||||
from certbot import interfaces
|
||||
from certbot import main
|
||||
from certbot import updater
|
||||
|
||||
from certbot.plugins import selection
|
||||
|
||||
|
|
@ -87,39 +88,33 @@ class RenewUpdaterTest(unittest.TestCase):
|
|||
mock_select.return_value = (mock_tls_installer, None)
|
||||
with mock.patch('certbot.main._init_le_client'):
|
||||
main.renew_cert(config, None, mock.MagicMock())
|
||||
#self.assertEqual(mock_tls_installer.callcounter.call_count, 2)
|
||||
self.assertTrue(mock_tls_installer.restart.called)
|
||||
|
||||
mock_tls_installer.restart.reset_mock()
|
||||
mock_tls_installer.callcounter.reset_mock()
|
||||
mock_tls_installer.renewed = []
|
||||
|
||||
main.run_renewal_updaters(config, None, lineage)
|
||||
#self.assertEqual(mock_tls_installer.callcounter.call_count, 2)
|
||||
updater.run_renewal_updaters(config, None, lineage)
|
||||
self.assertFalse(mock_tls_installer.restart.called)
|
||||
|
||||
# Generic Updater
|
||||
mock_select.return_value = (mock_generic_updater, None)
|
||||
with mock.patch('certbot.main._init_le_client'):
|
||||
main.renew_cert(config, None, mock.MagicMock())
|
||||
#self.assertEqual(mock_generic_updater.callcounter.call_count, 2)
|
||||
self.assertTrue(mock_generic_updater.restart.called)
|
||||
|
||||
mock_generic_updater.restart.reset_mock()
|
||||
mock_generic_updater.callcounter.reset_mock()
|
||||
mock_generic_updater.renewed = []
|
||||
|
||||
main.run_renewal_updaters(config, None, lineage)
|
||||
updater.run_renewal_updaters(config, None, lineage)
|
||||
self.assertEqual(mock_generic_updater.callcounter.call_count, 2)
|
||||
self.assertFalse(mock_generic_updater.restart.called)
|
||||
self.assertFalse(any(mock_generic_updater.renewed))
|
||||
|
||||
def test_renew_deployer(self):
|
||||
config = self.get_config({"installer_updates": True})
|
||||
lineage = mock.MagicMock()
|
||||
lineage.names.return_value = ['firstdomain', 'seconddomain']
|
||||
mock_deployer = self.renew_deployer
|
||||
main._run_renewal_deployer(lineage, mock_deployer, config)
|
||||
updater.run_renewal_deployer(lineage, mock_deployer, config)
|
||||
self.assertTrue(mock_deployer.callcounter.called_with(lineage))
|
||||
|
||||
|
||||
|
|
|
|||
69
certbot/updater.py
Normal file
69
certbot/updater.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
"""Updaters run at renewal"""
|
||||
import logging
|
||||
|
||||
from certbot import errors
|
||||
from certbot import interfaces
|
||||
|
||||
from certbot.plugins import selection as plug_sel
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def run_renewal_updaters(config, plugins, lineage):
|
||||
"""Run updaters that the plugin supports
|
||||
|
||||
:param config: Configuration object
|
||||
:type config: interfaces.IConfig
|
||||
|
||||
:param plugins: List of plugins
|
||||
:type plugins: `list` of `str`
|
||||
|
||||
:param lineage: Certificate lineage object
|
||||
:type lineage: storage.RenewableCert
|
||||
|
||||
:returns: `None`
|
||||
:rtype: None
|
||||
"""
|
||||
try:
|
||||
# installers are used in auth mode to determine domain names
|
||||
installer, _ = plug_sel.choose_configurator_plugins(config, plugins, "certonly")
|
||||
except errors.PluginSelectionError as e:
|
||||
logger.info("Could not choose appropriate plugin: %s", e)
|
||||
raise
|
||||
_run_updaters(lineage, installer, config)
|
||||
|
||||
def run_renewal_deployer(lineage, installer, config):
|
||||
"""Helper function to run deployer interface method if supported by the used
|
||||
installer plugin.
|
||||
|
||||
:param lineage: Certificate lineage object
|
||||
:type lineage: storage.RenewableCert
|
||||
|
||||
:param installer: Installer object
|
||||
:type installer: interfaces.IInstaller
|
||||
|
||||
:returns: `None`
|
||||
:rtype: None
|
||||
"""
|
||||
if config.installer_updates and isinstance(installer, interfaces.RenewDeployer):
|
||||
installer.renew_deploy(lineage)
|
||||
|
||||
def _run_updaters(lineage, installer, config):
|
||||
"""Helper function to run the updater interface methods if supported by the
|
||||
used installer plugin.
|
||||
|
||||
:param lineage: Certificate lineage object
|
||||
:type lineage: storage.RenewableCert
|
||||
|
||||
:param installer: Installer object
|
||||
:type installer: interfaces.IInstaller
|
||||
|
||||
:returns: `None`
|
||||
:rtype: None
|
||||
"""
|
||||
for domain in lineage.names():
|
||||
if config.server_tls_updates:
|
||||
if isinstance(installer, interfaces.ServerTLSUpdater):
|
||||
installer.server_tls_updates(domain)
|
||||
if config.installer_updates:
|
||||
if isinstance(installer, interfaces.GenericUpdater):
|
||||
installer.generic_updates(domain)
|
||||
Loading…
Reference in a new issue