mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 00:22:04 +02:00
Changed the errors import
This commit is contained in:
+17
-22
@@ -29,6 +29,7 @@ from letsencrypt import configuration
|
|||||||
from letsencrypt import constants
|
from letsencrypt import constants
|
||||||
from letsencrypt import client
|
from letsencrypt import client
|
||||||
from letsencrypt import crypto_util
|
from letsencrypt import crypto_util
|
||||||
|
from letsencrypt import errors
|
||||||
from letsencrypt import interfaces
|
from letsencrypt import interfaces
|
||||||
from letsencrypt import le_util
|
from letsencrypt import le_util
|
||||||
from letsencrypt import log
|
from letsencrypt import log
|
||||||
@@ -37,12 +38,6 @@ from letsencrypt import storage
|
|||||||
|
|
||||||
from letsencrypt.display import util as display_util
|
from letsencrypt.display import util as display_util
|
||||||
from letsencrypt.display import ops as display_ops
|
from letsencrypt.display import ops as display_ops
|
||||||
from letsencrypt.errors import (
|
|
||||||
CertStorageError,
|
|
||||||
ConfigurationError,
|
|
||||||
Error,
|
|
||||||
PluginSelectionError
|
|
||||||
)
|
|
||||||
from letsencrypt.plugins import disco as plugins_disco
|
from letsencrypt.plugins import disco as plugins_disco
|
||||||
|
|
||||||
|
|
||||||
@@ -112,7 +107,7 @@ def _find_domains(args, installer):
|
|||||||
domains = args.domains
|
domains = args.domains
|
||||||
|
|
||||||
if not domains:
|
if not domains:
|
||||||
raise Error("Please specify --domains, or --installer that "
|
raise errors.Error("Please specify --domains, or --installer that "
|
||||||
"will help in domain names autodiscovery")
|
"will help in domain names autodiscovery")
|
||||||
|
|
||||||
return domains
|
return domains
|
||||||
@@ -165,9 +160,9 @@ def _determine_account(args, config):
|
|||||||
try:
|
try:
|
||||||
acc, acme = client.register(
|
acc, acme = client.register(
|
||||||
config, account_storage, tos_cb=_tos_cb)
|
config, account_storage, tos_cb=_tos_cb)
|
||||||
except Error as error:
|
except errors.Error as error:
|
||||||
logger.debug(error, exc_info=True)
|
logger.debug(error, exc_info=True)
|
||||||
raise Error(
|
raise errors.Error(
|
||||||
"Unable to register an account with ACME server")
|
"Unable to register an account with ACME server")
|
||||||
|
|
||||||
args.account = acc.id
|
args.account = acc.id
|
||||||
@@ -201,7 +196,7 @@ def _find_duplicative_certs(config, domains):
|
|||||||
try:
|
try:
|
||||||
full_path = os.path.join(configs_dir, renewal_file)
|
full_path = os.path.join(configs_dir, renewal_file)
|
||||||
candidate_lineage = storage.RenewableCert(full_path, cli_config)
|
candidate_lineage = storage.RenewableCert(full_path, cli_config)
|
||||||
except (CertStorageError, IOError):
|
except (errors.CertStorageError, IOError):
|
||||||
logger.warning("Renewal configuration file %s is broken. "
|
logger.warning("Renewal configuration file %s is broken. "
|
||||||
"Skipping.", full_path)
|
"Skipping.", full_path)
|
||||||
continue
|
continue
|
||||||
@@ -273,7 +268,7 @@ def _treat_as_renewal(config, domains):
|
|||||||
br=os.linesep
|
br=os.linesep
|
||||||
),
|
),
|
||||||
reporter_util.HIGH_PRIORITY)
|
reporter_util.HIGH_PRIORITY)
|
||||||
raise Error(
|
raise errors.Error(
|
||||||
"User did not use proper CLI and would like "
|
"User did not use proper CLI and would like "
|
||||||
"to reinvoke the client.")
|
"to reinvoke the client.")
|
||||||
|
|
||||||
@@ -333,7 +328,7 @@ def _auth_from_domains(le_client, config, domains, plugins):
|
|||||||
# TREAT AS NEW REQUEST
|
# TREAT AS NEW REQUEST
|
||||||
lineage = le_client.obtain_and_enroll_certificate(domains, plugins)
|
lineage = le_client.obtain_and_enroll_certificate(domains, plugins)
|
||||||
if not lineage:
|
if not lineage:
|
||||||
raise Error("Certificate could not be obtained")
|
raise errors.Error("Certificate could not be obtained")
|
||||||
|
|
||||||
_report_new_cert(lineage.cert, lineage.fullchain)
|
_report_new_cert(lineage.cert, lineage.fullchain)
|
||||||
|
|
||||||
@@ -352,7 +347,7 @@ def set_configurator(previously, now):
|
|||||||
if previously:
|
if previously:
|
||||||
if previously != now:
|
if previously != now:
|
||||||
msg = "Too many flags setting configurators/installers/authenticators {0} -> {1}"
|
msg = "Too many flags setting configurators/installers/authenticators {0} -> {1}"
|
||||||
raise PluginSelectionError(msg.format(repr(previously), repr(now)))
|
raise errors.PluginSelectionError(msg.format(repr(previously), repr(now)))
|
||||||
return now
|
return now
|
||||||
|
|
||||||
|
|
||||||
@@ -385,7 +380,7 @@ def diagnose_configurator_problem(cfg_type, requested, plugins):
|
|||||||
'"letsencrypt-auto certonly" to get a cert you can install manually')
|
'"letsencrypt-auto certonly" to get a cert you can install manually')
|
||||||
else:
|
else:
|
||||||
msg = "{0} could not be determined or is not installed".format(cfg_type)
|
msg = "{0} could not be determined or is not installed".format(cfg_type)
|
||||||
raise PluginSelectionError(msg)
|
raise errors.PluginSelectionError(msg)
|
||||||
|
|
||||||
|
|
||||||
def choose_configurator_plugins(args, config, plugins, verb):
|
def choose_configurator_plugins(args, config, plugins, verb):
|
||||||
@@ -445,7 +440,7 @@ def run(args, config, plugins): # pylint: disable=too-many-branches,too-many-lo
|
|||||||
"""Obtain a certificate and install."""
|
"""Obtain a certificate and install."""
|
||||||
try:
|
try:
|
||||||
installer, authenticator = choose_configurator_plugins(args, config, plugins, "run")
|
installer, authenticator = choose_configurator_plugins(args, config, plugins, "run")
|
||||||
except PluginSelectionError, e:
|
except errors.PluginSelectionError, e:
|
||||||
return e.message
|
return e.message
|
||||||
|
|
||||||
domains = _find_domains(args, installer)
|
domains = _find_domains(args, installer)
|
||||||
@@ -478,7 +473,7 @@ def obtaincert(args, config, plugins):
|
|||||||
try:
|
try:
|
||||||
# installers are used in auth mode to determine domain names
|
# installers are used in auth mode to determine domain names
|
||||||
installer, authenticator = choose_configurator_plugins(args, config, plugins, "certonly")
|
installer, authenticator = choose_configurator_plugins(args, config, plugins, "certonly")
|
||||||
except PluginSelectionError, e:
|
except errors.PluginSelectionError, e:
|
||||||
return e.message
|
return e.message
|
||||||
|
|
||||||
# TODO: Handle errors from _init_le_client?
|
# TODO: Handle errors from _init_le_client?
|
||||||
@@ -503,7 +498,7 @@ def install(args, config, plugins):
|
|||||||
try:
|
try:
|
||||||
installer, _ = choose_configurator_plugins(args, config,
|
installer, _ = choose_configurator_plugins(args, config,
|
||||||
plugins, "install")
|
plugins, "install")
|
||||||
except PluginSelectionError, e:
|
except errors.PluginSelectionError, e:
|
||||||
return e.message
|
return e.message
|
||||||
|
|
||||||
domains = _find_domains(args, installer)
|
domains = _find_domains(args, installer)
|
||||||
@@ -1066,7 +1061,7 @@ def _handle_exception(exc_type, exc_value, trace, args):
|
|||||||
sys.exit("".join(
|
sys.exit("".join(
|
||||||
traceback.format_exception(exc_type, exc_value, trace)))
|
traceback.format_exception(exc_type, exc_value, trace)))
|
||||||
|
|
||||||
if issubclass(exc_type, Error):
|
if issubclass(exc_type, errors.Error):
|
||||||
sys.exit(exc_value)
|
sys.exit(exc_value)
|
||||||
else:
|
else:
|
||||||
# Tell the user a bit about what happened, without overwhelming
|
# Tell the user a bit about what happened, without overwhelming
|
||||||
@@ -1132,7 +1127,7 @@ def main(cli_args=sys.argv[1:]):
|
|||||||
disclaimer = pkg_resources.resource_string("letsencrypt", "DISCLAIMER")
|
disclaimer = pkg_resources.resource_string("letsencrypt", "DISCLAIMER")
|
||||||
if not zope.component.getUtility(interfaces.IDisplay).yesno(
|
if not zope.component.getUtility(interfaces.IDisplay).yesno(
|
||||||
disclaimer, "Agree", "Cancel"):
|
disclaimer, "Agree", "Cancel"):
|
||||||
raise Error("Must agree to TOS")
|
raise errors.Error("Must agree to TOS")
|
||||||
|
|
||||||
if not os.geteuid() == 0:
|
if not os.geteuid() == 0:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
@@ -1159,14 +1154,14 @@ def check_config_sanity(args):
|
|||||||
if args.domains is not None:
|
if args.domains is not None:
|
||||||
# Check if there's a wildcard domain
|
# Check if there's a wildcard domain
|
||||||
if any(True for d in args.domains if d.startswith("*.")):
|
if any(True for d in args.domains if d.startswith("*.")):
|
||||||
raise ConfigurationError("Error: Wildcard domains are not supported")
|
raise errors.ConfigurationError("Error: Wildcard domains are not supported")
|
||||||
# Punycode
|
# Punycode
|
||||||
if any(True for d in args.domains if "xn--" in d):
|
if any(True for d in args.domains if "xn--" in d):
|
||||||
raise ConfigurationError("Error: Punycode domains are not supported")
|
raise errors.ConfigurationError("Error: Punycode domains are not supported")
|
||||||
# Check for FQDN
|
# Check for FQDN
|
||||||
fqdn = re.compile("^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}$")
|
fqdn = re.compile("^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}$")
|
||||||
if any(True for d in args.domains if not fqdn.match(d)):
|
if any(True for d in args.domains if not fqdn.match(d)):
|
||||||
raise ConfigurationError("Error: Requested domain is not FQDN")
|
raise errors.ConfigurationError("Error: Requested domain is not FQDN")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
err_string = main()
|
err_string = main()
|
||||||
|
|||||||
Reference in New Issue
Block a user