From 6eac178122d2d607c7e44a867a4c6d31b9dd96fc Mon Sep 17 00:00:00 2001 From: Shankari Date: Tue, 10 Sep 2024 23:05:55 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Change=20the=20way=20in=20which?= =?UTF-8?q?=20we=20read=20the=20configuration=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The changes made to support the new configuration methodology failed with this error ``` ERROR:root:name 'os' is not defined Traceback (most recent call last): File "/usr/src/app/emission/net/ext_service/push/notify_interface.py", line 27, in logging.warning(f"Push configured for app {push_config.get('PUSH_APP_PACKAGE_NAME')} using platform {os.getenv('PUSH_PROVIDER')} with token {os.getenv('PUSH_SERVER_AUTH_TOKEN')[:10]}... of length {len(os.getenv('PUSH_SERVER_AUTH_TOKEN'))}") NameError: name 'os' is not defined ``` The fix is simply to use `push_config.get` instead of `os.getenv`. Also logged the full exception instead of simply generating a warning that the functionality is not supported. Testing done: - Before: error above - After: ``` Found configuration, overriding... Activating the environment... Run trip labeling reminder... WARNING:root:About to read push configuration... WARNING:root:Push configured for app gov.nrel.cims.openpath using platform firebase with token ... of length 152 ``` --- emission/net/ext_service/push/notify_interface.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/emission/net/ext_service/push/notify_interface.py b/emission/net/ext_service/push/notify_interface.py index c23e55d7e..04ed5d18d 100644 --- a/emission/net/ext_service/push/notify_interface.py +++ b/emission/net/ext_service/push/notify_interface.py @@ -24,8 +24,9 @@ "PUSH_APP_PACKAGE_NAME": "app_package_name", "PUSH_IOS_TOKEN_FORMAT": "ios_token_format"}) try: - 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(f"Push configured for app {push_config.get('PUSH_APP_PACKAGE_NAME')} using platform {push_config.get('PUSH_PROVIDER')} with token {push_config.get('PUSH_SERVER_AUTH_TOKEN')[:10]}... of length {len(push_config.get('PUSH_SERVER_AUTH_TOKEN'))}") +except Exception as e: + logging.exception(e) logging.warning("push service not configured, push notifications not supported") class NotifyInterfaceFactory(object):