Skip to content

Commit

Permalink
Copy over the server_auth into the firebase module
Browse files Browse the repository at this point in the history
As part of #980
(and
5a8ca40
in particular), we initialize the firebase module with the values we read from
the config.

However, we removed the initialization of the `server_auth_token`
https://github.com/e-mission/e-mission-server/pull/980/files#diff-5a90853314b14f3bec03976fa2ba81ec657e6327b770e9b376cfeabc0544487eL24

This is no longer used to send the actual notification, but it is used to map
the FCM tokens to APNS.

Note this is working for some deployments (e.g. nrel_commute) but not for other (e.g. stage). I can confirm that I get reminder notifications on my personal android phone. I don't understand how this ever worked - before #980, we weren't using the HTTP v1 version so no notifications were sent.  After the  change, this should have prevented notifications from being sent out.

Testing done.

Before the change

```
Connecting to database URL ...
Traceback (most recent call last):
  File "/usr/src/app/bin/push/silent_ios_push.py", line 24, in <module>
    response = pnu.send_silent_notification_to_ios_with_interval(args.interval, dev=args.dev)
  File "/usr/src/app/emission/net/ext_service/push/notify_usage.py", line 41, in send_silent_notification_to_ios_with_interval
    return __get_default_interface__().send_silent_notification(token_map, {}, dev)
  File "/usr/src/app/emission/net/ext_service/push/notify_interface_impl/firebase.py", line 194, in send_silent_notification
    fcm_token_map = self.convert_to_fcm_if_necessary(token_map, dev)
  File "/usr/src/app/emission/net/ext_service/push/notify_interface_impl/firebase.py", line 137, in convert_to_fcm_if_necessary
    importedResultList = self.retrieve_fcm_tokens(unmapped_token_list, dev)
  File "/usr/src/app/emission/net/ext_service/push/notify_interface_impl/firebase.py", line 98, in retrieve_fcm_tokens
    importHeaders = {"Authorization": "key=%s" % self.server_auth_token,
AttributeError: 'FirebasePush' object has no attribute 'server_auth_token'
```

After the change

```
Config file not found, returning a copy of the environment variables instead...
Retrieved config: {'DB_HOST': '...', 'DB_RESULT_LIMIT': None}
Connecting to database URL ...
Received invalid result for batch starting at = 0
after mapping iOS tokens, imported 0 -> processed 0
combo token map has 30 ios entries and 0 android entries
Successfully sent to ...
Successfully sent to ...
Successfully sent to ...
Found error Token not registered while sending to token ... skipping
Successfully sent to ...
Successfully sent to ...
Found error Token not registered while sending to token ... skipping
Successfully sent to ...
Successfully sent to -3sW...
Found error Token not registered while sending to token ... skipping
Successfully sent to ...
```
  • Loading branch information
shankari committed Oct 6, 2024
1 parent 250c26e commit e06895b
Showing 1 changed file with 1 addition and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def get_interface(push_config):
class FirebasePush(pni.NotifyInterface):
def __init__(self, push_config):
self.service_account_file = push_config.get("PUSH_SERVICE_ACCOUNT_FILE")
self.server_auth_token = push_config.get("PUSH_SERVER_AUTH_TOKEN")
self.project_id = push_config.get("PUSH_PROJECT_ID")
if "PUSH_APP_PACKAGE_NAME" in push_config:
self.app_package_name = push_config.get("PUSH_APP_PACKAGE_NAME")
Expand Down

0 comments on commit e06895b

Please sign in to comment.