Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unrecognized errors in guest create #929

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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