Coverage for certbot/plugins/selection.py : 84%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""Decide which plugins to use for authentication & installation"""
config, default, plugins, question="How would you like to authenticate and install " "certificates?"): """Pick configurator plugin.""" config, default, plugins, question, (interfaces.IAuthenticator, interfaces.IInstaller))
question="How would you like to install certificates?"): """Pick installer plugin.""" config, default, plugins, question, (interfaces.IInstaller,))
config, default, plugins, question="How would you " "like to authenticate with the ACME CA?"): """Pick authentication plugin.""" config, default, plugins, question, (interfaces.IAuthenticator,))
""" Get an unprepared interfaces.IInstaller object.
:param certbot.interfaces.IConfig config: Configuration :param certbot.plugins.disco.PluginsRegistry plugins: All plugins registered as entry points.
:returns: Unprepared installer plugin or None :rtype: IPlugin or None """
"Found multiple installers with the name %s, Certbot is unable to " "determine which one to use. Skipping." % req_inst) else: "Could not select or initialize the requested installer %s." % req_inst)
"""Pick plugin.
:param certbot.interfaces.IConfig: Configuration :param str default: Plugin name supplied by user or ``None``. :param certbot.plugins.disco.PluginsRegistry plugins: All plugins registered as entry points. :param str question: Question to be presented to the user in case multiple candidates are found. :param list ifaces: Interfaces that plugins must provide.
:returns: Initialized plugin. :rtype: IPlugin
""" # throw more UX-friendly error if default not in plugins else: # it's really bad to auto-select the single available plugin in # non-interactive mode, because an update could later add a second # available plugin "Missing command line flags. For non-interactive execution, " "you will need to specify a plugin on the command line. Run " "with '--help plugins' to see a list of options, and see " "https://eff.org/letsencrypt-plugins for more detail on what " "the plugins do and how to use them.")
else: else:
"""Allow the user to choose their plugin.
:param list prepared: List of `~.PluginEntryPoint`. :param str question: Question to be presented to the user.
:returns: Plugin entry point chosen by the user. :rtype: `~.PluginEntryPoint`
""" (" [Misconfigured]" if plugin_ep.misconfigured else "") for plugin_ep in prepared]
# The possibility of being offered exactly apache and nginx here # is new interactivity brought by https://github.com/certbot/certbot/issues/4079, # so set apache as a default for those kinds of non-interactive use # (the user will get a warning to set --non-interactive or --force-interactive) else:
"The selected plugin encountered an error while parsing " "your server configuration and cannot be used. The error " "was:\n\n{0}".format(plugin_ep.prepare()), pause=False) else: else:
"dns-digitalocean", "dns-dnsimple", "dns-dnsmadeeasy", "dns-gehirn", "dns-google", "dns-linode", "dns-luadns", "dns-nsone", "dns-ovh", "dns-rfc2136", "dns-route53", "dns-sakuracloud"]
"Update the config entries to reflect the plugins we actually selected." config.authenticator, config.installer)
# pylint: disable=too-many-branches """ Figure out which configurator we're going to use, modifies config.authenticator and config.installer strings to reflect that choice if necessary.
:raises errors.PluginSelectionError if there was a problem
:returns: (an `IAuthenticator` or None, an `IInstaller` or None) :rtype: tuple """
"configure the selected enhancements?")
# Which plugins do we need? '{1} {2} certonly --{0}{1}{1}' '(Alternatively, add a --installer flag. See https://eff.org/letsencrypt-plugins' '{1} and "--help plugins" for more information.)'.format( req_auth, os.linesep, cli_command))
else: "running Certbot with verb \"%s\"", verb) # Try to meet the user's request and/or ask them to pick plugins # Unless the user has explicitly asked for different auth/install, # only consider offering a single choice authenticator = installer = pick_configurator(config, req_inst, plugins) else:
# Report on any failures diagnose_configurator_problem("installer", req_inst, plugins)
""" Setting configurators multiple ways is okay, as long as they all agree :param str previously: previously identified request for the installer/authenticator :param str requested: the request currently being processed """ # we're not actually setting anything if previously != now: msg = "Too many flags setting configurators/installers/authenticators {0} -> {1}" raise errors.PluginSelectionError(msg.format(repr(previously), repr(now)))
""" Figure out which plugins the user requested with CLI and config options
:returns: (requested authenticator string or None, requested installer string or None) :rtype: tuple """
req_inst = set_configurator(req_inst, "nginx") req_auth = set_configurator(req_auth, "nginx") req_inst = set_configurator(req_inst, "apache") req_auth = set_configurator(req_auth, "apache") req_auth = set_configurator(req_auth, "dns-cloudflare") req_auth = set_configurator(req_auth, "dns-cloudxns") req_auth = set_configurator(req_auth, "dns-digitalocean") req_auth = set_configurator(req_auth, "dns-dnsimple") req_auth = set_configurator(req_auth, "dns-dnsmadeeasy") req_auth = set_configurator(req_auth, "dns-gehirn") req_auth = set_configurator(req_auth, "dns-google") req_auth = set_configurator(req_auth, "dns-linode") req_auth = set_configurator(req_auth, "dns-luadns") req_auth = set_configurator(req_auth, "dns-nsone") req_auth = set_configurator(req_auth, "dns-ovh") req_auth = set_configurator(req_auth, "dns-rfc2136") req_auth = set_configurator(req_auth, "dns-route53") req_auth = set_configurator(req_auth, "dns-sakuracloud")
""" Raise the most helpful error message about a plugin being unavailable
:param str cfg_type: either "installer" or "authenticator" :param str requested: the plugin that was requested :param .PluginsRegistry plugins: available plugins
:raises error.PluginSelectionError: if there was a problem """
else: msg = ("The {0} plugin is not working; there may be problems with " "your existing configuration.\nThe error was: {1!r}" .format(requested, plugins[requested].problem)) elif cfg_type == "installer": from certbot.cli import cli_command msg = ('Certbot doesn\'t know how to automatically configure the web ' 'server on this system. However, it can still get a certificate for ' 'you. Please run "{0} certonly" to do so. You\'ll need to ' 'manually configure your web server to use the resulting ' 'certificate.').format(cli_command) else: msg = "{0} could not be determined or is not installed".format(cfg_type) |