mirror of
https://github.com/certbot/certbot.git
synced 2026-07-28 08:45:22 +02:00
Update Certbot dependency to Lexicon to 3.x (#6593)
This PR updates Lexicon dependency to the latest version available, 3.0.6, for every lexicon-based DNS plugins. It updates also the provider construction to use the new ConfigResolverobject, and to remove the legacy configuration process.
This commit is contained in:
committed by
Brad Warren
parent
8cf3bcd3f3
commit
651de2dd2f
@@ -1,12 +1,22 @@
|
||||
"""Common code for DNS Authenticator Plugins built on Lexicon."""
|
||||
|
||||
import logging
|
||||
|
||||
from requests.exceptions import HTTPError, RequestException
|
||||
|
||||
from acme.magic_typing import Union, Dict, Any # pylint: disable=unused-import,no-name-in-module
|
||||
from certbot import errors
|
||||
from certbot.plugins import dns_common
|
||||
|
||||
# Lexicon is not declared as a dependency in Certbot itself,
|
||||
# but in the Certbot plugins backed by Lexicon.
|
||||
# So we catch import error here to allow this module to be
|
||||
# always importable, even if it does not make sense to use it
|
||||
# if Lexicon is not available, obviously.
|
||||
try:
|
||||
from lexicon.config import ConfigResolver
|
||||
except ImportError:
|
||||
ConfigResolver = None # type: ignore
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -100,3 +110,28 @@ class LexiconClient(object):
|
||||
if not str(e).startswith('No domain found'):
|
||||
return errors.PluginError('Unexpected error determining zone identifier for {0}: {1}'
|
||||
.format(domain_name, e))
|
||||
|
||||
|
||||
def build_lexicon_config(lexicon_provider_name, lexicon_options, provider_options):
|
||||
# type: (str, Dict, Dict) -> Union[ConfigResolver, Dict]
|
||||
"""
|
||||
Convenient function to build a Lexicon 2.x/3.x config object.
|
||||
:param str lexicon_provider_name: the name of the lexicon provider to use
|
||||
:param dict lexicon_options: options specific to lexicon
|
||||
:param dict provider_options: options specific to provider
|
||||
:return: configuration to apply to the provider
|
||||
:rtype: ConfigurationResolver or dict
|
||||
"""
|
||||
config = {'provider_name': lexicon_provider_name} # type: Dict[str, Any]
|
||||
config.update(lexicon_options)
|
||||
if not ConfigResolver:
|
||||
# Lexicon 2.x
|
||||
config.update(provider_options)
|
||||
else:
|
||||
# Lexicon 3.x
|
||||
provider_config = {}
|
||||
provider_config.update(provider_options)
|
||||
config[lexicon_provider_name] = provider_config
|
||||
config = ConfigResolver().with_dict(config).with_env()
|
||||
|
||||
return config
|
||||
|
||||
Reference in New Issue
Block a user