mirror of
https://github.com/certbot/certbot.git
synced 2026-08-02 19:31:51 +02:00
Added message and changed reporter interface
This commit is contained in:
@@ -92,13 +92,13 @@ def report_new_account(acc, config):
|
|||||||
"contain certificates and private keys obtained by Let's Encrypt "
|
"contain certificates and private keys obtained by Let's Encrypt "
|
||||||
"so making regular backups of this folder is ideal.".format(
|
"so making regular backups of this folder is ideal.".format(
|
||||||
config.config_dir),
|
config.config_dir),
|
||||||
reporter.MEDIUM_PRIORITY, True)
|
reporter.MEDIUM_PRIORITY)
|
||||||
|
|
||||||
if acc.regr.body.emails:
|
if acc.regr.body.emails:
|
||||||
recovery_msg = ("If you lose your account credentials, you can "
|
recovery_msg = ("If you lose your account credentials, you can "
|
||||||
"recover through e-mails sent to {0}.".format(
|
"recover through e-mails sent to {0}.".format(
|
||||||
", ".join(acc.regr.body.emails)))
|
", ".join(acc.regr.body.emails)))
|
||||||
reporter.add_message(recovery_msg, reporter.HIGH_PRIORITY, True)
|
reporter.add_message(recovery_msg, reporter.HIGH_PRIORITY)
|
||||||
|
|
||||||
|
|
||||||
class AccountMemoryStorage(interfaces.AccountStorage):
|
class AccountMemoryStorage(interfaces.AccountStorage):
|
||||||
|
|||||||
@@ -531,7 +531,7 @@ def _report_failed_challs(failed_achalls):
|
|||||||
reporter = zope.component.getUtility(interfaces.IReporter)
|
reporter = zope.component.getUtility(interfaces.IReporter)
|
||||||
for achalls in problems.itervalues():
|
for achalls in problems.itervalues():
|
||||||
reporter.add_message(
|
reporter.add_message(
|
||||||
_generate_failed_chall_msg(achalls), reporter.MEDIUM_PRIORITY, True)
|
_generate_failed_chall_msg(achalls), reporter.MEDIUM_PRIORITY)
|
||||||
|
|
||||||
|
|
||||||
def _generate_failed_chall_msg(failed_achalls):
|
def _generate_failed_chall_msg(failed_achalls):
|
||||||
|
|||||||
@@ -267,6 +267,14 @@ def _treat_as_renewal(config, domains):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _report_new_cert(cert_path):
|
||||||
|
"""Reports the creation of a new certificate to the user."""
|
||||||
|
reporter_util = zope.component.getUtility(interfaces.IReporter)
|
||||||
|
reporter_util.add_message("Congratulations! Your certificate has been "
|
||||||
|
"saved at {0}.".format(cert_path),
|
||||||
|
reporter.MEDIUM_PRIORITY)
|
||||||
|
|
||||||
|
|
||||||
def _auth_from_domains(le_client, config, domains, plugins):
|
def _auth_from_domains(le_client, config, domains, plugins):
|
||||||
"""Authenticate and enroll certificate."""
|
"""Authenticate and enroll certificate."""
|
||||||
# Note: This can raise errors... caught above us though.
|
# Note: This can raise errors... caught above us though.
|
||||||
@@ -292,6 +300,8 @@ def _auth_from_domains(le_client, config, domains, plugins):
|
|||||||
if not lineage:
|
if not lineage:
|
||||||
raise errors.Error("Certificate could not be obtained")
|
raise errors.Error("Certificate could not be obtained")
|
||||||
|
|
||||||
|
_report_new_cert(lineage.cert)
|
||||||
|
|
||||||
return lineage
|
return lineage
|
||||||
|
|
||||||
|
|
||||||
@@ -365,6 +375,7 @@ def auth(args, config, plugins):
|
|||||||
file=args.csr[0], data=args.csr[1], form="der"))
|
file=args.csr[0], data=args.csr[1], form="der"))
|
||||||
le_client.save_certificate(
|
le_client.save_certificate(
|
||||||
certr, chain, args.cert_path, args.chain_path)
|
certr, chain, args.cert_path, args.chain_path)
|
||||||
|
_report_new_cert(args.cert_path)
|
||||||
else:
|
else:
|
||||||
domains = _find_domains(args, installer)
|
domains = _find_domains(args, installer)
|
||||||
_auth_from_domains(le_client, config, domains, plugins)
|
_auth_from_domains(le_client, config, domains, plugins)
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ class Client(object):
|
|||||||
"configured in the directories under {0}.").format(
|
"configured in the directories under {0}.").format(
|
||||||
cert.cli_config.renewal_configs_dir)
|
cert.cli_config.renewal_configs_dir)
|
||||||
reporter = zope.component.getUtility(interfaces.IReporter)
|
reporter = zope.component.getUtility(interfaces.IReporter)
|
||||||
reporter.add_message(msg, reporter.LOW_PRIORITY, True)
|
reporter.add_message(msg, reporter.LOW_PRIORITY)
|
||||||
|
|
||||||
def save_certificate(self, certr, chain_cert, cert_path, chain_path):
|
def save_certificate(self, certr, chain_cert, cert_path, chain_path):
|
||||||
# pylint: disable=no-self-use
|
# pylint: disable=no-self-use
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ class IReporter(zope.interface.Interface):
|
|||||||
LOW_PRIORITY = zope.interface.Attribute(
|
LOW_PRIORITY = zope.interface.Attribute(
|
||||||
"Used to denote low priority messages")
|
"Used to denote low priority messages")
|
||||||
|
|
||||||
def add_message(self, msg, priority, on_crash=False):
|
def add_message(self, msg, priority, on_crash=True):
|
||||||
"""Adds msg to the list of messages to be printed.
|
"""Adds msg to the list of messages to be printed.
|
||||||
|
|
||||||
:param str msg: Message to be displayed to the user.
|
:param str msg: Message to be displayed to the user.
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class Reporter(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.messages = Queue.PriorityQueue()
|
self.messages = Queue.PriorityQueue()
|
||||||
|
|
||||||
def add_message(self, msg, priority, on_crash=False):
|
def add_message(self, msg, priority, on_crash=True):
|
||||||
"""Adds msg to the list of messages to be printed.
|
"""Adds msg to the list of messages to be printed.
|
||||||
|
|
||||||
:param str msg: Message to be displayed to the user.
|
:param str msg: Message to be displayed to the user.
|
||||||
|
|||||||
@@ -78,13 +78,13 @@ class ReporterTest(unittest.TestCase):
|
|||||||
output = sys.stdout.getvalue()
|
output = sys.stdout.getvalue()
|
||||||
self.assertTrue("IMPORTANT NOTES:" in output)
|
self.assertTrue("IMPORTANT NOTES:" in output)
|
||||||
self.assertTrue("High" in output)
|
self.assertTrue("High" in output)
|
||||||
self.assertTrue("Med" not in output)
|
self.assertTrue("Med" in output)
|
||||||
self.assertTrue("Low" not in output)
|
self.assertTrue("Low" not in output)
|
||||||
|
|
||||||
def _add_messages(self):
|
def _add_messages(self):
|
||||||
self.reporter.add_message("High", self.reporter.HIGH_PRIORITY, True)
|
self.reporter.add_message("High", self.reporter.HIGH_PRIORITY)
|
||||||
self.reporter.add_message("Med", self.reporter.MEDIUM_PRIORITY)
|
self.reporter.add_message("Med", self.reporter.MEDIUM_PRIORITY)
|
||||||
self.reporter.add_message("Low", self.reporter.LOW_PRIORITY)
|
self.reporter.add_message("Low", self.reporter.LOW_PRIORITY, False)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user