Skip to content

Commit

Permalink
fix: Login for Globus SDK v3.3.x
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NickolausDS committed Feb 7, 2022
1 parent 8b8b9b0 commit 20e8231
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions globus_portal_framework/gclients.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -44,17 +48,21 @@ 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]:
err = ('Service {} has no service url for the '
'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):
Expand Down

0 comments on commit 20e8231

Please sign in to comment.