Skip to content

Commit

Permalink
Update to be compatible with SDK 3.46+
Browse files Browse the repository at this point in the history
  • Loading branch information
sirosen committed Oct 21, 2024
1 parent aeced44 commit e64ceec
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def s3(
gcs_client = login_manager.get_gcs_client(endpoint_id=endpoint_id)
auth_client = login_manager.get_auth_client()

# TODO: replace with SDK class once available
# TODO: replace with SDK class if one becomes available
policies = {
"DATA_TYPE": "s3_user_credential_policies#1.0.0",
"s3_key_id": s3_key_id,
Expand Down
17 changes: 5 additions & 12 deletions src/globus_cli/commands/flows/run/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
# NB: GARE parsing requires other SDK components and therefore needs to be deferred to
# avoid the performance impact of non-lazy imports
if t.TYPE_CHECKING:
from globus_sdk.experimental.auth_requirements_error import (
GlobusAuthRequirementsError,
)
from globus_sdk.gare import GARE


@command("resume")
Expand Down Expand Up @@ -66,7 +64,7 @@ def resume_command(
def check_inactive_reason(
login_manager: LoginManager,
run_id: uuid.UUID,
gare: GlobusAuthRequirementsError | None,
gare: GARE | None,
) -> None:
if gare is None:
return
Expand Down Expand Up @@ -109,13 +107,8 @@ def check_inactive_reason(

def _get_inactive_reason(
run_doc: dict[str, t.Any] | globus_sdk.GlobusHTTPResponse
) -> GlobusAuthRequirementsError | None:
try:
from globus_sdk.gare import to_gare # type: ignore[import-not-found]
except ImportError:
from globus_sdk.experimental.auth_requirements_error import (
to_auth_requirements_error as to_gare,
)
) -> GARE | None:
from globus_sdk.gare import to_gare

if not run_doc.get("status") == "INACTIVE":
return None
Expand All @@ -124,7 +117,7 @@ def _get_inactive_reason(
if not isinstance(details, dict):
return None

return to_gare(details) # type: ignore[no-any-return]
return to_gare(details)


def _has_required_consent(
Expand Down
17 changes: 5 additions & 12 deletions src/globus_cli/commands/timer/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
# NB: GARE parsing requires other SDK components and therefore needs to be deferred to
# avoid the performance impact of non-lazy imports
if t.TYPE_CHECKING:
from globus_sdk.experimental.auth_requirements_error import (
GlobusAuthRequirementsError,
)
from globus_sdk.gare import GARE


@command("resume", short_help="Resume a timer.")
Expand Down Expand Up @@ -59,7 +57,7 @@ def resume_command(
def check_inactive_reason(
login_manager: LoginManager,
timer_id: uuid.UUID,
gare: GlobusAuthRequirementsError | None,
gare: GARE | None,
) -> None:
if gare is None:
return
Expand Down Expand Up @@ -102,13 +100,8 @@ def check_inactive_reason(

def _get_inactive_reason(
timer_doc: dict[str, t.Any] | globus_sdk.GlobusHTTPResponse
) -> GlobusAuthRequirementsError | None:
try:
from globus_sdk.gare import to_gare # type: ignore[import-not-found]
except ImportError:
from globus_sdk.experimental.auth_requirements_error import (
to_auth_requirements_error as to_gare,
)
) -> GARE | None:
from globus_sdk.gare import to_gare

if timer_doc.get("status") != "inactive":
return None
Expand All @@ -117,7 +110,7 @@ def _get_inactive_reason(
if reason.get("cause") != "globus_auth_requirements":
return None

return to_gare(reason.get("detail", {})) # type: ignore[no-any-return]
return to_gare(reason.get("detail", {}))


def _has_required_consent(
Expand Down
15 changes: 3 additions & 12 deletions src/globus_cli/login_manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@
TimersScopes,
TransferScopes,
)

# TODO: remove this after an SDK release provides scopes.consents
try:
from globus_sdk.scopes.consents import ( # type: ignore[import-not-found]
ConsentForest,
)
except ImportError:
from globus_sdk.experimental.consents import ConsentForest
from globus_sdk.scopes.consents import ConsentForest

from globus_cli.endpointish import Endpointish, EntityType
from globus_cli.types import ServiceNameLiteral
Expand Down Expand Up @@ -183,9 +176,7 @@ def _tokens_meet_nonstatic_requirements(
else:
# If there are dependent scopes all required scope paths are present in the
# user's cached consent forest.
return ( # type: ignore[no-any-return]
self._cached_consent_forest.meets_scope_requirements(required_scopes)
)
return self._cached_consent_forest.meets_scope_requirements(required_scopes)

@property
@functools.lru_cache(maxsize=1) # noqa: B019
Expand Down Expand Up @@ -304,7 +295,7 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:

def _get_client_authorizer(
self, resource_server: str, *, no_tokens_msg: str | None = None
) -> globus_sdk.authorizers.RenewingAuthorizer:
) -> globus_sdk.ClientCredentialsAuthorizer | globus_sdk.RefreshTokenAuthorizer:
tokens = self._token_storage.get_token_data(resource_server)

if is_client_login():
Expand Down
2 changes: 1 addition & 1 deletion src/globus_cli/services/transfer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CustomTransferClient(globus_sdk.TransferClient):
def __init__(
self,
*,
authorizer: globus_sdk.GlobusAuthorizer,
authorizer: globus_sdk.authorizers.GlobusAuthorizer,
app_name: str,
) -> None:
super().__init__(authorizer=authorizer, app_name=app_name)
Expand Down
7 changes: 1 addition & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@
import responses
from click.testing import CliRunner
from globus_sdk._testing import register_response_set
from globus_sdk.scopes import TimersScopes
from globus_sdk.transport import RequestsTransport
from ruamel.yaml import YAML

import globus_cli
from globus_cli.login_manager.tokenstore import build_storage_adapter

# TODO: remove this after an SDK release provides TimersScopes
try:
from globus_sdk.scopes import TimersScopes
except ImportError:
from globus_sdk.scopes import TimerScopes as TimersScopes

yaml = YAML()
log = logging.getLogger(__name__)

Expand Down
10 changes: 6 additions & 4 deletions tests/functional/groups/test_group_set_policies.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import json

import pytest
import responses
from globus_sdk._testing import load_response_set, register_response_set
from globus_sdk._testing import (
get_last_request,
load_response_set,
register_response_set,
)


@pytest.fixture(autouse=True, scope="session")
Expand Down Expand Up @@ -62,8 +65,7 @@ def test_group_set_policies(run_line, add_args, field_name, expected_value):
result = run_line(["globus", "group", "set-policies", group_id] + add_args)
assert "Group policies updated successfully" in result.output

# TODO: expose get_last_request in globus_sdk._testing ?
last_req = responses.calls[-1].request
last_req = get_last_request()
body = json.loads(last_req.body)

# confirm expected put body values
Expand Down

0 comments on commit e64ceec

Please sign in to comment.