Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update aioapns dependency to one that supports python 3.10+ #347

Merged
merged 4 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/347.misc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to convince myself this was safe, it seems that we really need >= 2.1 to support Python 3.10.

Bumping to 3.0 itself is probably fine though.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump aioapns dependency to 3.0 in order to support Python 3.10+.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ authors = [
{name = "Matrix.org Team and contributors", email = "[email protected]"}
]
dependencies = [
"aioapns>=1.10,<2.1",
"aioapns>=3.0",
"attrs>=19.2.0",
"cryptography>=2.6.1",
"idna>=2.8",
Expand Down
53 changes: 28 additions & 25 deletions sygnal/apnspushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -262,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",
Expand Down