mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 19:02:52 +02:00
refactor _restore_required_config_elements
This commit is contained in:
+43
-24
@@ -1,6 +1,7 @@
|
|||||||
"""Functionality for autorenewal and associated juggling of configurations"""
|
"""Functionality for autorenewal and associated juggling of configurations"""
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import copy
|
import copy
|
||||||
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
@@ -157,30 +158,48 @@ def _restore_required_config_elements(config, renewalparams):
|
|||||||
configuration file that defines this lineage
|
configuration file that defines this lineage
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# string-valued items to add if they're present
|
required_items = itertools.chain(
|
||||||
for config_item in STR_CONFIG_ITEMS:
|
six.moves.zip(INT_CONFIG_ITEMS, itertools.repeat(_restore_int)),
|
||||||
if config_item in renewalparams and not cli.set_by_cli(config_item):
|
six.moves.zip(STR_CONFIG_ITEMS, itertools.repeat(_restore_str)))
|
||||||
value = renewalparams[config_item]
|
for item_name, restore_func in required_items:
|
||||||
# Unfortunately, we've lost type information from ConfigObj,
|
if item_name in renewalparams and not cli.set_by_cli(item_name):
|
||||||
# so we don't know if the original was NoneType or str!
|
value = restore_func(item_name, renewalparams[item_name])
|
||||||
if value == "None":
|
setattr(config.namespace, item_name, value)
|
||||||
value = None
|
|
||||||
setattr(config.namespace, config_item, value)
|
|
||||||
# int-valued items to add if they're present
|
def _restore_int(name, value):
|
||||||
for config_item in INT_CONFIG_ITEMS:
|
"""Restores an integer key-value pair from a renewal config file.
|
||||||
if config_item in renewalparams and not cli.set_by_cli(config_item):
|
|
||||||
config_value = renewalparams[config_item]
|
:param str name: option name
|
||||||
# the default value for http01_port was None during private beta
|
:param str value: option value
|
||||||
if config_item == "http01_port" and config_value == "None":
|
|
||||||
logger.info("updating legacy http01_port value")
|
:returns: converted option value to be stored in the runtime config
|
||||||
int_value = cli.flag_default("http01_port")
|
:rtype: int
|
||||||
else:
|
|
||||||
try:
|
:raises errors.Error: if value can't be converted to an int
|
||||||
int_value = int(config_value)
|
|
||||||
except ValueError:
|
"""
|
||||||
raise errors.Error(
|
if name == "http01_port" and value == "None":
|
||||||
"Expected a numeric value for {0}".format(config_item))
|
logger.info("updating legacy http01_port value")
|
||||||
setattr(config.namespace, config_item, int_value)
|
return cli.flag_default("http01_port")
|
||||||
|
|
||||||
|
try:
|
||||||
|
return int(value)
|
||||||
|
except ValueError:
|
||||||
|
raise errors.Error("Expected a numeric value for {0}".format(name))
|
||||||
|
|
||||||
|
|
||||||
|
def _restore_str(unused_name, value):
|
||||||
|
"""Restores an string key-value pair from a renewal config file.
|
||||||
|
|
||||||
|
:param str unused_name: option name
|
||||||
|
:param str value: option value
|
||||||
|
|
||||||
|
:returns: converted option value to be stored in the runtime config
|
||||||
|
:rtype: str or None
|
||||||
|
|
||||||
|
"""
|
||||||
|
return None if value == "None" else value
|
||||||
|
|
||||||
|
|
||||||
def should_renew(config, lineage):
|
def should_renew(config, lineage):
|
||||||
|
|||||||
Reference in New Issue
Block a user