Merge remote-tracking branch 'origin/renew_verb' into issue_2347

This commit is contained in:
Peter Eckersley
2016-02-05 17:34:45 -08:00
+42 -30
View File
@@ -704,6 +704,12 @@ def obtain_cert(config, plugins, lineage=None):
if config.dry_run: if config.dry_run:
_report_successful_dry_run() _report_successful_dry_run()
elif config.verb == "renew" and installer is not None:
# In case of a renewal, reload server to pick up new certificate.
# In principle we could have a configuration option to inhibit this
# from happening.
installer.restart()
print("reloaded")
_suggest_donation_if_appropriate(config) _suggest_donation_if_appropriate(config)
@@ -782,31 +788,32 @@ def _restore_plugin_configs(config, renewalparams, default_detector_conf):
# works as long as plugins don't need to read plugin-specific # works as long as plugins don't need to read plugin-specific
# variables set by someone else (e.g., assuming Apache # variables set by someone else (e.g., assuming Apache
# configurator doesn't need to read webroot_ variables). # configurator doesn't need to read webroot_ variables).
# XXX: is it true that an item will end up in _parser._actions even # Note: if a parameter that used to be defined in the parser is no
# when no action was explicitly specified? # longer defined, stored copies of that parameter will be
# deserialized as strings by this logic even if they were
# originally meant to be some other type.
plugin_prefixes = [renewalparams["authenticator"]] plugin_prefixes = [renewalparams["authenticator"]]
if "installer" in renewalparams and renewalparams["installer"] != None: if renewalparams.get("installer", None) is not None:
plugin_prefixes.append(renewalparams["installer"]) plugin_prefixes.append(renewalparams["installer"])
for plugin_prefix in set(renewalparams): for plugin_prefix in set(plugin_prefixes):
for config_item in renewalparams.keys(): for config_item, config_value in renewalparams.iteritems():
if renewalparams[config_item] == "None": if config_item.startswith(plugin_prefix + "_") and not _diff_from_default(
default_detector_conf, config_item):
# Avoid confusion when, for example, "csr = None" (avoid # Avoid confusion when, for example, "csr = None" (avoid
# trying to read the file called "None") # trying to read the file called "None")
# Should we omit the item entirely rather than setting # Should we omit the item entirely rather than setting
# its value to None? # its value to None?
setattr(config.namespace, config_item, None) if config_value == "None":
continue setattr(config.namespace, config_item, None)
if config_item.startswith(plugin_prefix + "_") and not _diff_from_default( continue
default_detector_conf, config_item):
for action in _parser.parser._actions: # pylint: disable=protected-access for action in _parser.parser._actions: # pylint: disable=protected-access
if action.type is not None and action.dest == config_item: if action.type is not None and action.dest == config_item:
setattr(config.namespace, config_item, setattr(config.namespace, config_item,
action.type(renewalparams[config_item])) action.type(config_value))
break break
else: else:
setattr(config.namespace, config_item, setattr(config.namespace, config_item, str(config_value))
str(renewalparams[config_item]))
return True
def _reconstitute(config, full_path, default_detector_conf): def _reconstitute(config, full_path, default_detector_conf):
@@ -901,8 +908,6 @@ def renew(config, plugins):
renewer_config = configuration.RenewerConfiguration(config) renewer_config = configuration.RenewerConfiguration(config)
for renewal_file in _renewal_conf_files(renewer_config): for renewal_file in _renewal_conf_files(renewer_config):
if not renewal_file.endswith(".conf"):
continue
print("Processing " + renewal_file) print("Processing " + renewal_file)
# XXX: does this succeed in making a fully independent config object # XXX: does this succeed in making a fully independent config object
# each time? # each time?
@@ -920,20 +925,27 @@ def renew(config, plugins):
logger.debug("Traceback was:\n%s", traceback.format_exc()) logger.debug("Traceback was:\n%s", traceback.format_exc())
continue continue
if renewal_candidate is None: try:
# reconstitute indicated an error or problem which has if renewal_candidate is not None:
# already been logged. Go on to the next config. # _reconstitute succeeded in producing a RenewableCert, so we
continue # have something to work with from this particular config file.
# XXX: ensure that each call here replaces the previous one
zope.component.provideUtility(lineage_config) # XXX: ensure that each call here replaces the previous one
zope.component.provideUtility(lineage_config)
print("Trying...")
# Because obtain_cert itself indirectly decides whether to renew
# or not, we couldn't currently make a UI/logging distinction at
# this stage to indicate whether renewal was actually attempted
# (or successful).
obtain_cert(lineage_config,
plugins_disco.PluginsRegistry.find_all(),
renewal_candidate)
except Exception as e: # pylint: disable=broad-except
# obtain_cert (presumably) encountered an unanticipated problem.
logger.warning("Attempting to renew cert from %s produced an "
"unexpected error: %s. Skipping.", renewal_file, e)
logger.debug("Traceback was:\n%s", traceback.format_exc())
print("Trying...")
# Because obtain_cert itself indirectly decides whether to renew
# or not, we couldn't currently make a UI/logging distinction at
# this stage to indicate whether renewal was actually attempted
# (or successful).
obtain_cert(lineage_config, plugins_disco.PluginsRegistry.find_all(),
renewal_candidate)
def revoke(config, unused_plugins): # TODO: coop with renewal config def revoke(config, unused_plugins): # TODO: coop with renewal config
"""Revoke a previously obtained certificate.""" """Revoke a previously obtained certificate."""
@@ -1654,7 +1666,7 @@ def setup_log_file_handler(config, logfile, fmt):
def _cli_log_handler(config, level, fmt): def _cli_log_handler(config, level, fmt):
if config.text_mode: if config.text_mode or config.noninteractive_mode or config.verb == "renew":
handler = colored_logging.StreamHandler() handler = colored_logging.StreamHandler()
handler.setFormatter(logging.Formatter(fmt)) handler.setFormatter(logging.Formatter(fmt))
else: else: