Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Convert acme.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Jul 30, 2020
1 parent 3aa36b7 commit b94de14
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.d/7989.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Convert various parts of the codebase to async/await.
13 changes: 6 additions & 7 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,12 @@ def setup(config_options):

hs.setup_master()

@defer.inlineCallbacks
def do_acme():
async def do_acme() -> bool:
"""
Reprovision an ACME certificate, if it's required.
Returns:
Deferred[bool]: Whether the cert has been updated.
Whether the cert has been updated.
"""
acme = hs.get_acme_handler()

Expand All @@ -405,7 +404,7 @@ def do_acme():
provision = True

if provision:
yield acme.provision_certificate()
await acme.provision_certificate()

return provision

Expand All @@ -415,7 +414,7 @@ def reprovision_acme():
Provision a certificate from ACME, if required, and reload the TLS
certificate if it's renewed.
"""
reprovisioned = yield do_acme()
reprovisioned = yield defer.ensureDeferred(do_acme())
if reprovisioned:
_base.refresh_certificate(hs)

Expand All @@ -427,8 +426,8 @@ def start():
acme = hs.get_acme_handler()
# Start up the webservices which we will respond to ACME
# challenges with, and then provision.
yield acme.start_listening()
yield do_acme()
yield defer.ensureDeferred(acme.start_listening())
yield defer.ensureDeferred(do_acme())

# Check if it needs to be reprovisioned every day.
hs.get_clock().looping_call(reprovision_acme, 24 * 60 * 60 * 1000)
Expand Down
11 changes: 4 additions & 7 deletions synapse/handlers/acme.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import twisted
import twisted.internet.error
from twisted.internet import defer
from twisted.web import server, static
from twisted.web.resource import Resource

Expand All @@ -41,8 +40,7 @@ def __init__(self, hs):
self.reactor = hs.get_reactor()
self._acme_domain = hs.config.acme_domain

@defer.inlineCallbacks
def start_listening(self):
async def start_listening(self):
from synapse.handlers import acme_issuing_service

# Configure logging for txacme, if you need to debug
Expand Down Expand Up @@ -82,18 +80,17 @@ def start_listening(self):
self._issuer._registered = False

try:
yield self._issuer._ensure_registered()
await self._issuer._ensure_registered()
except Exception:
logger.error(ACME_REGISTER_FAIL_ERROR)
raise

@defer.inlineCallbacks
def provision_certificate(self):
async def provision_certificate(self):

logger.warning("Reprovisioning %s", self._acme_domain)

try:
yield self._issuer.issue_cert(self._acme_domain)
await self._issuer.issue_cert(self._acme_domain)
except Exception:
logger.exception("Fail!")
raise
Expand Down

0 comments on commit b94de14

Please sign in to comment.