From 1560fd46805571032e0ba77814121423bd27b7d3 Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Mon, 29 Aug 2016 12:41:55 -0700 Subject: [PATCH] cleanup pref_challs help, use consistent naming, and simplify parsing --- certbot/cli.py | 53 ++++++++++++++++------------------------------- certbot/client.py | 2 +- 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/certbot/cli.py b/certbot/cli.py index a0cd9b173..c236041ce 100644 --- a/certbot/cli.py +++ b/certbot/cli.py @@ -11,10 +11,10 @@ import sys import configargparse import six -import certbot - from acme import challenges +import certbot + from certbot import constants from certbot import crypto_util from certbot import errors @@ -847,12 +847,13 @@ def prepare_and_parse_args(plugins, args, detect_defaults=False): # pylint: dis help="Require that all configuration files are owned by the current " "user; only needed if your config is somewhere unsafe like /tmp/") helpful.add( - "security", "--preferred-challenges", dest="pref_chall", - action=_PrefChallAction, default=[], - help="Specify which challenges you'd prefer to use. If any of those " - "challenges are valid for your authenticator they will be used. " - "Otherwise Certbot will not attempt authorization. The first " - "challenge listed that is supported by the plugin will be used.") + ["certonly", "renew", "run"], "--preferred-challenges", + dest="pref_challs", action=_PrefChallAction, default=[], + help="A sorted, comma delimited list of the preferred challenge to " + "use during authorization with the most preferred challenge " + "listed first (e.g. tls-sni-01,http-01). If none of the " + "preferred challenges can be used by the selected plugin to " + "satisfy the CA, authorization is not attempted.") helpful.add( "renew", "--pre-hook", help="Command to be run in a shell before obtaining any certificates." @@ -1045,30 +1046,12 @@ def add_domains(args_or_config, domains): class _PrefChallAction(argparse.Action): """Action class for parsing preferred challenges.""" - def __call__(self, parser, namespace, pref_chall, option_string=None): - """Just wrap add_pref_challs in argparseese.""" - _ = add_pref_challs(namespace, pref_chall) - -def add_pref_challs(namespace, pref_challs): - """Parses and validates user specified challenge types. - - Adds challenges (in order) to the configuration object. - - :param namespace: parsed command line arguments - :type namespace: argparse.Namespace or - configuration.NamespaceConfig - :param str pref_challs: one or more comma separated challenge types - - :returns: Challenge objects which match the validated string inputs - :rtype: `list` - """ - challs = pref_challs.split(",") - unrecognized = [name for name in challs if name not in challenges.Challenge.TYPES] - if unrecognized: - raise argparse.ArgumentTypeError( - "Unrecognized challenges: {0}".format(", ".join(unrecognized))) - - out = [challenges.Challenge.TYPES[name] for name in challs] - print(namespace) - namespace.pref_chall.extend(out) - return out + def __call__(self, parser, namespace, pref_challs, option_string=None): + challs = pref_challs.split(",") + unrecognized = ", ".join(name for name in challs + if name not in challenges.Challenge.TYPES) + if unrecognized: + raise argparse.ArgumentTypeError( + "Unrecognized challenges: {0}".format(unrecognized)) + namespace.pref_challs.extend(challenges.Challenge.TYPES[name] + for name in challs) diff --git a/certbot/client.py b/certbot/client.py index 66e90bb1f..44eb67e48 100644 --- a/certbot/client.py +++ b/certbot/client.py @@ -192,7 +192,7 @@ class Client(object): if auth is not None: self.auth_handler = auth_handler.AuthHandler( - auth, self.acme, self.account, self.config.pref_chall) + auth, self.acme, self.account, self.config.pref_challs) else: self.auth_handler = None