From a0f0c6a66524c18733ae8239203701b3ce21cd98 Mon Sep 17 00:00:00 2001 From: Shankari Date: Sun, 11 Aug 2024 17:30:25 -0700 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20Move=20the=20push=20con?= =?UTF-8?q?figuration=20into=20the=20backwards=20compat=20as=20well?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consistent with https://github.com/e-mission/e-mission-server/pull/961#issuecomment-2282206511 and - 3dea305184796fdd662e0faf3cedb72f49b3d44c (example for the api) - 7f1be920098f644d863536a5e810343f2634fc28 (original example for the database) Testing done: ``` $ ./e-mission-py.bash emission/tests/netTests/TestPush.py ---------------------------------------------------------------------- Ran 5 tests in 0.276s OK ``` --- emission/net/ext_service/push/notify_interface.py | 10 +++++++--- .../ext_service/push/notify_interface_impl/firebase.py | 8 ++++---- emission/tests/netTests/TestPush.py | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/emission/net/ext_service/push/notify_interface.py b/emission/net/ext_service/push/notify_interface.py index d38a213b1..b8080bc74 100644 --- a/emission/net/ext_service/push/notify_interface.py +++ b/emission/net/ext_service/push/notify_interface.py @@ -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): diff --git a/emission/net/ext_service/push/notify_interface_impl/firebase.py b/emission/net/ext_service/push/notify_interface_impl/firebase.py index 34593f82f..6ce7eb8e3 100644 --- a/emission/net/ext_service/push/notify_interface_impl/firebase.py +++ b/emission/net/ext_service/push/notify_interface_impl/firebase.py @@ -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 diff --git a/emission/tests/netTests/TestPush.py b/emission/tests/netTests/TestPush.py index 43684a33b..2b6ef636c 100644 --- a/emission/tests/netTests/TestPush.py +++ b/emission/tests/netTests/TestPush.py @@ -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) @@ -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)