cleanup pref_challs help, use consistent naming, and simplify parsing

This commit is contained in:
Brad Warren
2016-08-29 12:41:55 -07:00
parent d4f81f825c
commit 1560fd4680
2 changed files with 19 additions and 36 deletions
+18 -35
View File
@@ -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)
+1 -1
View File
@@ -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