Skip to content

Commit

Permalink
Merge pull request #929 from sirosen/handle-non-dict-gcs-detail
Browse files Browse the repository at this point in the history
Handle unrecognized errors in guest create
  • Loading branch information
sirosen authored Jan 4, 2024
2 parents 48f3fba + 619e626 commit 7d5399a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Bugfixes

* Fix the error handling when `globus gcs collection create guest` encounters a
non-session error.
6 changes: 5 additions & 1 deletion src/globus_cli/commands/collection/create/guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ def _is_session_timeout_error(e: globus_sdk.GCSAPIError) -> bool:
Detect session timeouts related to HA collections.
This is a hacky workaround until we have better GARE support across the CLI.
"""
detail_type = getattr(e, "detail", {}).get("DATA_TYPE")
detail = getattr(e, "detail", {})
if not isinstance(detail, dict):
return False

detail_type = detail.get("DATA_TYPE")
return (
e.http_status == 403
and isinstance(detail_type, str)
Expand Down
41 changes: 41 additions & 0 deletions tests/functional/collection/test_collection_create_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,44 @@ def test_guest_collection_create__when_session_times_out_against_ha_mapped_colle

assert "Session timeout detected; Re-authentication required." in result.stderr
assert f"globus login --gcs {endpoint_id} --force" in result.stderr


def test_guest_collection_create__when_gcs_emits_unrecognized_error(
run_line,
mock_user_data,
add_gcs_login,
):
meta = load_response_set("cli.collection_operations").metadata
mapped_collection_id = meta["mapped_collection_id"]
display_name = meta["guest_display_name"]
gcs_hostname = meta["gcs_hostname"]
endpoint_id = meta["endpoint_id"]
add_gcs_login(endpoint_id)

create_guest_collection_route = f"https://{gcs_hostname}/api/collections"
responses.replace(
"POST",
create_guest_collection_route,
status=403,
json={
"DATA_TYPE": "result#1.0.0",
"code": "permission_denied",
"detail": "oh noez!",
"has_next_page": False,
"http_response_code": 403,
"message": "Oh noez! You must authenticate much better!",
},
)

get_endpoint_route = (
f"{get_service_url('transfer')}v0.10/endpoint/{mapped_collection_id}"
)
get_endpoint_resp = requests.get(get_endpoint_route).json()
get_endpoint_resp["high_assurance"] = True
responses.replace("GET", get_endpoint_route, json=get_endpoint_resp)

params = f"{mapped_collection_id} /home/ '{display_name}'"
result = run_line(f"globus collection create guest {params}", assert_exit_code=1)

assert "Session timeout detected" not in result.stderr
assert "Oh noez! You must authenticate much better!" in result.stderr

0 comments on commit 7d5399a

Please sign in to comment.