From 20e82311436a64d06facf01b27cb75095ec978b4 Mon Sep 17 00:00:00 2001 From: "Nickolaus D. Saint" Date: Mon, 7 Feb 2022 15:23:24 -0800 Subject: [PATCH] fix: Login for Globus SDK v3.3.x Older DGPF components to enable Preview relied on internal components of the Globus SDK. The last change in v3.3.0 to make them public broke compatibility with earlier versions. This change adds one last check to ensure that v3.3.x+ versions should work as well. The next version of Globus Portal Framework should remove all of this when dropping support for earlier versions of the SDK. --- globus_portal_framework/gclients.py | 32 ++++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/globus_portal_framework/gclients.py b/globus_portal_framework/gclients.py index 39206559..d41aad53 100644 --- a/globus_portal_framework/gclients.py +++ b/globus_portal_framework/gclients.py @@ -1,5 +1,6 @@ import requests from datetime import timedelta +from packaging.version import Version from django.utils import timezone from django.conf import settings from django.utils.module_loading import import_string @@ -12,6 +13,10 @@ log = logging.getLogger(__name__) +GLOBUS_SDK_VERSION = Version(globus_sdk.version.__version__) + +# This is legacy code for pre SDK-v3.3.x versions, it will be removed in the +# next version of DGPF. CUSTOM_ENVS = { 'groups': { # Globus SDK v2 @@ -22,20 +27,19 @@ } } -# At this point, 'groups' is still a beta service for Globus. -# This will likely be folded into the Globus SDK at some point, but needs -# to be hardcoded here in the mean time. +# This is present in the latest v3 version of the Globus SDK +# and will be removed in the next version. GROUPS_SCOPE = ('urn:globus:auth:scope:groups.api.globus.org:' 'view_my_groups_and_memberships') GLOBUS_GROUPS_V2_MY_GROUPS = '/v2/groups/my_groups' def get_globus_environment(): - """Get the current Globus Environment. Used primarily for checking whether - the user has set GLOBUS_SDK_ENVIRONMENT=preview from the Globus SDK, but - may also be used for other Globus Environments. See here for more info: - Globus Preview: https://docs.globus.org/how-to/preview/ - Globus SDK: https://globus-sdk-python.readthedocs.io/en/stable/config.html?highlight=preview#environment-variables # noqa + """ + This is needed to support prior versions of the Globus SDK < 3.3.x, please + use the following for determining service urls instead: + + https://globus-sdk-python.readthedocs.io/en/stable/config.html#config-related-functions # noqqa """ try: return globus_sdk.config.get_globus_environ() @@ -44,9 +48,10 @@ def get_globus_environment(): def get_service_url(service_name): - """Get the URL based on the current Globus Environment. Is a wrapper around - The Globus SDK .get_service_url(), but also provides lookup for custom beta - services such as Globus Groups.""" + """This is needed for backwards compatibility with earlier versions of the + Globus SDK. Use the following supported function in the Globus SDK instead: + https://globus-sdk-python.readthedocs.io/en/stable/config.html#globus_sdk.config.get_service_url # noqa + """ env = get_globus_environment() if service_name in CUSTOM_ENVS: if env not in CUSTOM_ENVS[service_name]: @@ -54,7 +59,10 @@ def get_service_url(service_name): 'configured environment: "{}"'.format(service_name, env)) raise exc.GlobusPortalException('InvalidEnv', err) return CUSTOM_ENVS[service_name][env] - return globus_sdk.config.get_service_url(env, service_name) + if GLOBUS_SDK_VERSION.major == 3 and GLOBUS_SDK_VERSION.minor in [0, 1, 2]: + return globus_sdk.config.get_service_url(env, service_name) + elif GLOBUS_SDK_VERSION.major == 3 and GLOBUS_SDK_VERSION.minor >= 3: + return globus_sdk.config.get_service_url(service_name) def validate_token(tok):