From d33c452954929e43ac0c20aa041adda4b0c53d64 Mon Sep 17 00:00:00 2001 From: Brad Murray Date: Tue, 5 Sep 2023 15:59:22 -0400 Subject: [PATCH 1/4] Update aioapns dependency to one that supports python 3.10+ --- pyproject.toml | 2 +- sygnal/apnspushkin.py | 51 +++++++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ca1122b5..bf7d85f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,7 +74,7 @@ authors = [ {name = "Matrix.org Team and contributors", email = "packages@matrix.org"} ] dependencies = [ - "aioapns>=1.10,<2.1", + "aioapns>=3.0", "attrs>=19.2.0", "cryptography>=2.6.1", "idna>=2.8", diff --git a/sygnal/apnspushkin.py b/sygnal/apnspushkin.py index f3a41cec..0bb66ad5 100644 --- a/sygnal/apnspushkin.py +++ b/sygnal/apnspushkin.py @@ -172,31 +172,34 @@ def __init__(self, name: str, sygnal: "Sygnal", config: Dict[str, Any]) -> None: # this overrides the create_connection method to use a HTTP proxy loop = ProxyingEventLoopWrapper(loop, proxy_url_str) # type: ignore - if certfile is not None: - # max_connection_attempts is actually the maximum number of - # additional connection attempts, so =0 means try once only - # (we will retry at a higher level so not worth doing more here) - self.apns_client = APNs( - client_cert=certfile, - use_sandbox=self.use_sandbox, - max_connection_attempts=0, - loop=loop, - ) + async def make_apns() -> aioapns.APNs: + if certfile is not None: + # max_connection_attempts is actually the maximum number of + # additional connection attempts, so =0 means try once only + # (we will retry at a higher level so not worth doing more here) + apns_client = APNs( + client_cert=certfile, + use_sandbox=self.use_sandbox, + max_connection_attempts=0, + ) - self._report_certificate_expiration(certfile) - else: - # max_connection_attempts is actually the maximum number of - # additional connection attempts, so =0 means try once only - # (we will retry at a higher level so not worth doing more here) - self.apns_client = APNs( - key=self.get_config("keyfile", str), - key_id=self.get_config("key_id", str), - team_id=self.get_config("team_id", str), - topic=self.get_config("topic", str), - use_sandbox=self.use_sandbox, - max_connection_attempts=0, - loop=loop, - ) + self._report_certificate_expiration(certfile) + + return apns_client + else: + # max_connection_attempts is actually the maximum number of + # additional connection attempts, so =0 means try once only + # (we will retry at a higher level so not worth doing more here) + return APNs( + key=self.get_config("keyfile", str), + key_id=self.get_config("key_id", str), + team_id=self.get_config("team_id", str), + topic=self.get_config("topic", str), + use_sandbox=self.use_sandbox, + max_connection_attempts=0, + ) + + self.apns_client = loop.run_until_complete(make_apns()) push_type = self.get_config("push_type", str) if not push_type: From 196c4f94bd2ce6de3a48d846e1dffcd836aae275 Mon Sep 17 00:00:00 2001 From: Brad Murray Date: Wed, 6 Sep 2023 12:05:36 -0400 Subject: [PATCH 2/4] Add newsfile --- changelog.d/347.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/347.misc diff --git a/changelog.d/347.misc b/changelog.d/347.misc new file mode 100644 index 00000000..de1bdf56 --- /dev/null +++ b/changelog.d/347.misc @@ -0,0 +1 @@ +Bump aioapns dependency to 3.0 in order to support Python 3.10+ From 3f03a641296dd00c33a48ead3a5a03f4fdaa8e49 Mon Sep 17 00:00:00 2001 From: Brad Murray Date: Wed, 6 Sep 2023 12:09:24 -0400 Subject: [PATCH 3/4] Fix types in opentracing span with new version of aioapns --- sygnal/apnspushkin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sygnal/apnspushkin.py b/sygnal/apnspushkin.py index 0bb66ad5..92b77e13 100644 --- a/sygnal/apnspushkin.py +++ b/sygnal/apnspushkin.py @@ -265,7 +265,7 @@ async def _dispatch_request( return [] else: # .description corresponds to the 'reason' response field - span.set_tag("apns_reason", response.description) + span.set_tag("apns_reason", response.description or "None") if (code, response.description) in self.TOKEN_ERRORS: log.info( "APNs token %s for pushkin %s was rejected: %d %s", From 7c6bf595afde6352711c7aaf0ffe59729fd0e4b5 Mon Sep 17 00:00:00 2001 From: Brad Murray Date: Wed, 6 Sep 2023 13:01:30 -0400 Subject: [PATCH 4/4] Improve the newsfile --- changelog.d/347.misc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/347.misc b/changelog.d/347.misc index de1bdf56..23764652 100644 --- a/changelog.d/347.misc +++ b/changelog.d/347.misc @@ -1 +1 @@ -Bump aioapns dependency to 3.0 in order to support Python 3.10+ +Bump aioapns dependency to 3.0 in order to support Python 3.10+.