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

Migrate from apns2 to aioapns #721

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

Migrate from apns2 to aioapns #721

wants to merge 6 commits into from

Conversation

macro1
Copy link

@macro1 macro1 commented May 6, 2024

Disclaimer: I haven't tested this with real interactions with APNs.

The goal is to remove the indirect use of hyper (which is no longer maintained) and unblock compatibility with newer Python versions without breaking too many of the existing contracts.

I did remove the 'creds' parameter that existed in many of the functions. The value that would have been accepted is a part of apns2, so it cannot be realistically supported.

Somewhat surprising.. It seems the indentation is currently set to tabs? This PR currently converts several of the files, which may not be the right approach.

@macro1 macro1 closed this May 6, 2024
@macro1 macro1 reopened this May 6, 2024
@macro1
Copy link
Author

macro1 commented May 6, 2024

I closed this when I saw #696, but I'm re-opening it because the approaches are very different. This PR does a full replacement rather than adding an alternate APNS implementation.

@50-Course
Copy link
Member

i'd be following this development closely, and might have to re-base (#711) on this. Let me know if you need some help or require unblocking at some point.

Comment on lines +124 to +129
# converting to ttl for underlying library
if expiration:
time_to_live = expiration - int(time.time())
else:
time_to_live = 2592000

Copy link
Member

@50-Course 50-Course May 13, 2024

Choose a reason for hiding this comment

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

Nice catch here, Looks good! The code handles the case of an unspecified expiration clearly. I might have gone with the ternary approach as an improvement:

time_to_live = expiration - int(time.timeit()) if expiration else 2592000

Copy link
Member

Choose a reason for hiding this comment

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

👍🏼

key_id=key_id,
team_id=team_id,
use_sandbox=get_manager().get_apns_use_sandbox(application_id),
)

Choose a reason for hiding this comment

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

I found two errors. The topic isn't being sent when creating the client and the context processor raises an exception if there's no credential path. I tested it afterwards and works great with Django 4.2 and Python 3.11

if not get_manager().has_auth_token_creds(application_id): cert = get_manager().get_apns_certificate(application_id) with _apns_path_for_cert(cert) as cert_path: client = aioapns.APNs( client_cert=cert_path, team_id=team_id, topic=get_manager().get_apns_topic(application_id), use_sandbox=get_manager().get_apns_use_sandbox(application_id), ) else: key_path, key_id, team_id = get_manager().get_apns_auth_creds(application_id) client = aioapns.APNs( key=key_path, key_id=key_id, team_id=team_id, topic=get_manager().get_apns_topic(application_id), use_sandbox=get_manager().get_apns_use_sandbox(application_id), )

Copy link

@aalbinati aalbinati May 23, 2024

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Awesome. Thank you @aalbinati. Doing some testing with the service was on my to-do, I'll pull in the changes you're suggesting soon.

@DataGreed
Copy link
Contributor

Any updates on this? Is this going to be merged?

@@ -13,62 +13,80 @@ class APNSModelTestCase(TestCase):

def _create_devices(self, devices):
for device in devices:
print("created", device)

Choose a reason for hiding this comment

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

You left a print here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants