File: updater.py

package info (click to toggle)
python-certbot 0.31.0-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,152 kB
  • sloc: python: 17,551; makefile: 171; sh: 31
file content (122 lines) | stat: -rw-r--r-- 3,954 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""Updaters run at renewal"""
import logging

from certbot import errors
from certbot import interfaces

from certbot.plugins import selection as plug_sel
import certbot.plugins.enhancements as enhancements

logger = logging.getLogger(__name__)

def run_generic_updaters(config, lineage, plugins):
    """Run updaters that the plugin supports

    :param config: Configuration object
    :type config: interfaces.IConfig

    :param lineage: Certificate lineage object
    :type lineage: storage.RenewableCert

    :param plugins: List of plugins
    :type plugins: `list` of `str`

    :returns: `None`
    :rtype: None
    """
    if config.dry_run:
        logger.debug("Skipping updaters in dry-run mode.")
        return
    try:
        installer = plug_sel.get_unprepared_installer(config, plugins)
    except errors.Error as e:
        logger.warning("Could not choose appropriate plugin for updaters: %s", e)
        return
    if installer:
        _run_updaters(lineage, installer, config)
        _run_enhancement_updaters(lineage, installer, config)

def run_renewal_deployer(config, lineage, installer):
    """Helper function to run deployer interface method if supported by the used
    installer plugin.

    :param config: Configuration object
    :type config: interfaces.IConfig

    :param lineage: Certificate lineage object
    :type lineage: storage.RenewableCert

    :param installer: Installer object
    :type installer: interfaces.IInstaller

    :returns: `None`
    :rtype: None
    """
    if config.dry_run:
        logger.debug("Skipping renewal deployer in dry-run mode.")
        return

    if not config.disable_renew_updates and isinstance(installer,
                                                       interfaces.RenewDeployer):
        installer.renew_deploy(lineage)
    _run_enhancement_deployers(lineage, installer, config)

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
    """
    if not config.disable_renew_updates:
        if isinstance(installer, interfaces.GenericUpdater):
            installer.generic_updates(lineage)

def _run_enhancement_updaters(lineage, installer, config):
    """Iterates through known enhancement interfaces. If the installer implements
    an enhancement interface and the enhance interface has an updater method, the
    updater method gets run.

    :param lineage: Certificate lineage object
    :type lineage: storage.RenewableCert

    :param installer: Installer object
    :type installer: interfaces.IInstaller

    :param config: Configuration object
    :type config: interfaces.IConfig
    """

    if config.disable_renew_updates:
        return
    for enh in enhancements._INDEX:  # pylint: disable=protected-access
        if isinstance(installer, enh["class"]) and enh["updater_function"]:
            getattr(installer, enh["updater_function"])(lineage)


def _run_enhancement_deployers(lineage, installer, config):
    """Iterates through known enhancement interfaces. If the installer implements
    an enhancement interface and the enhance interface has an deployer method, the
    deployer method gets run.

    :param lineage: Certificate lineage object
    :type lineage: storage.RenewableCert

    :param installer: Installer object
    :type installer: interfaces.IInstaller

    :param config: Configuration object
    :type config: interfaces.IConfig
    """

    if config.disable_renew_updates:
        return
    for enh in enhancements._INDEX:  # pylint: disable=protected-access
        if isinstance(installer, enh["class"]) and enh["deployer_function"]:
            getattr(installer, enh["deployer_function"])(lineage)