mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 12:02:03 +02:00
cleanup pref_challs help, use consistent naming, and simplify parsing
This commit is contained in:
+18
-35
@@ -11,10 +11,10 @@ import sys
|
|||||||
import configargparse
|
import configargparse
|
||||||
import six
|
import six
|
||||||
|
|
||||||
import certbot
|
|
||||||
|
|
||||||
from acme import challenges
|
from acme import challenges
|
||||||
|
|
||||||
|
import certbot
|
||||||
|
|
||||||
from certbot import constants
|
from certbot import constants
|
||||||
from certbot import crypto_util
|
from certbot import crypto_util
|
||||||
from certbot import errors
|
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 "
|
help="Require that all configuration files are owned by the current "
|
||||||
"user; only needed if your config is somewhere unsafe like /tmp/")
|
"user; only needed if your config is somewhere unsafe like /tmp/")
|
||||||
helpful.add(
|
helpful.add(
|
||||||
"security", "--preferred-challenges", dest="pref_chall",
|
["certonly", "renew", "run"], "--preferred-challenges",
|
||||||
action=_PrefChallAction, default=[],
|
dest="pref_challs", action=_PrefChallAction, default=[],
|
||||||
help="Specify which challenges you'd prefer to use. If any of those "
|
help="A sorted, comma delimited list of the preferred challenge to "
|
||||||
"challenges are valid for your authenticator they will be used. "
|
"use during authorization with the most preferred challenge "
|
||||||
"Otherwise Certbot will not attempt authorization. The first "
|
"listed first (e.g. tls-sni-01,http-01). If none of the "
|
||||||
"challenge listed that is supported by the plugin will be used.")
|
"preferred challenges can be used by the selected plugin to "
|
||||||
|
"satisfy the CA, authorization is not attempted.")
|
||||||
helpful.add(
|
helpful.add(
|
||||||
"renew", "--pre-hook",
|
"renew", "--pre-hook",
|
||||||
help="Command to be run in a shell before obtaining any certificates."
|
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):
|
class _PrefChallAction(argparse.Action):
|
||||||
"""Action class for parsing preferred challenges."""
|
"""Action class for parsing preferred challenges."""
|
||||||
|
|
||||||
def __call__(self, parser, namespace, pref_chall, option_string=None):
|
def __call__(self, parser, namespace, pref_challs, option_string=None):
|
||||||
"""Just wrap add_pref_challs in argparseese."""
|
challs = pref_challs.split(",")
|
||||||
_ = add_pref_challs(namespace, pref_chall)
|
unrecognized = ", ".join(name for name in challs
|
||||||
|
if name not in challenges.Challenge.TYPES)
|
||||||
def add_pref_challs(namespace, pref_challs):
|
if unrecognized:
|
||||||
"""Parses and validates user specified challenge types.
|
raise argparse.ArgumentTypeError(
|
||||||
|
"Unrecognized challenges: {0}".format(unrecognized))
|
||||||
Adds challenges (in order) to the configuration object.
|
namespace.pref_challs.extend(challenges.Challenge.TYPES[name]
|
||||||
|
for name in challs)
|
||||||
: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
|
|
||||||
|
|||||||
+1
-1
@@ -192,7 +192,7 @@ class Client(object):
|
|||||||
|
|
||||||
if auth is not None:
|
if auth is not None:
|
||||||
self.auth_handler = auth_handler.AuthHandler(
|
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:
|
else:
|
||||||
self.auth_handler = None
|
self.auth_handler = None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user