Skip to content

Commit

Permalink
♻️ Move the push configuration into the backwards compat as well
Browse files Browse the repository at this point in the history
Consistent with
#961 (comment)
and
- 3dea305 (example for the api)
- 7f1be92 (original example for the database)

Testing done:

```
$ ./e-mission-py.bash emission/tests/netTests/TestPush.py
----------------------------------------------------------------------
Ran 5 tests in 0.276s

OK
```
  • Loading branch information
shankari committed Aug 12, 2024
1 parent 3dea305 commit a0f0c6a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
10 changes: 7 additions & 3 deletions emission/net/ext_service/push/notify_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@
import logging
import importlib

import emission.net.ext_service.push.config as pc
import emission.core.backwards_compat_config as ecbc

# Note that the URL is hardcoded because the API endpoints are not standardized.
# If we change a push provider, we will need to modify to match their endpoints.
# Hardcoding will remind us of this :)
# We can revisit this if push providers eventually decide to standardize...

push_config = ecbc.get_config('conf/net/ext_service/push.json',
{"PUSH_PROVIDER": "provider", "PUSH_SERVER_AUTH_TOKEN": "server_auth_token",
"PUSH_APP_PACKAGE_NAME": "app_package_name", "PUSH_IOS_TOKEN_FORMAT": "ios_token_format"})

try:
push_config = pc.get_config()
logging.info(f"Push configured for app {push_config.get('PUSH_SERVER_AUTH_TOKEN')} using platform {os.getenv('PUSH_PROVIDER')} with token {os.getenv('PUSH_SERVER_AUTH_TOKEN')[:10]}... of length {len(os.getenv('PUSH_SERVER_AUTH_TOKEN'))}")
except:
logging.warning("push service not configured, push notifications not supported")

class NotifyInterfaceFactory(object):
@staticmethod
def getDefaultNotifyInterface():
return NotifyInterfaceFactory.getNotifyInterface(push_config["provider"])
return NotifyInterfaceFactory.getNotifyInterface(push_config["PUSH_PROVIDER"])

@staticmethod
def getNotifyInterface(pushProvider):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def get_interface(push_config):

class FirebasePush(pni.NotifyInterface):
def __init__(self, push_config):
self.server_auth_token = push_config["server_auth_token"]
if "app_package_name" in push_config:
self.app_package_name = push_config["app_package_name"]
self.server_auth_token = push_config["PUSH_SERVER_AUTH_TOKEN"]
if "PUSH_APP_PACKAGE_NAME" in push_config:
self.app_package_name = push_config["PUSH_APP_PACKAGE_NAME"]
else:
logging.warning("No package name specified, defaulting to embase")
self.app_package_name = "edu.berkeley.eecs.embase"
self.is_fcm_format = push_config["ios_token_format"] == "fcm"
self.is_fcm_format = push_config["PUSH_IOS_TOKEN_FORMAT"] == "fcm"

def get_and_invalidate_entries(self):
# Need to figure out how to do this on firebase
Expand Down
4 changes: 2 additions & 2 deletions emission/tests/netTests/TestPush.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def testFcmMapping(self):
logging.debug("test token map = %s" % self.test_token_map)

try:
fcm_instance = pnif.get_interface({"server_auth_token": "firebase_api_key", "ios_token_format": "apns"})
fcm_instance = pnif.get_interface({"PUSH_SERVER_AUTH_TOKEN": "firebase_api_key", "PUSH_IOS_TOKEN_FORMAT": "apns"})
(mapped_token_map, unmapped_token_list) = fcm_instance.map_existing_fcm_tokens(self.test_token_map)
# At this point, there is nothing in the database, so no iOS tokens will be mapped
self.assertEqual(len(mapped_token_map["ios"]), 0)
Expand Down Expand Up @@ -176,7 +176,7 @@ def testFcmNoMapping(self):
"android": self.test_token_list_android}
logging.debug("test token map = %s" % self.test_token_map)

fcm_instance = pnif.get_interface({"server_auth_token": "firebase_api_key", "ios_token_format": "fcm"})
fcm_instance = pnif.get_interface({"PUSH_SERVER_AUTH_TOKEN": "firebase_api_key", "PUSH_IOS_TOKEN_FORMAT": "fcm"})
(mapped_token_map, unmapped_token_list) = fcm_instance.map_existing_fcm_tokens(self.test_token_map)
# These are assumed to be FCM tokens directly, so no mapping required
self.assertEqual(len(mapped_token_map["ios"]), 10)
Expand Down

0 comments on commit a0f0c6a

Please sign in to comment.