Skip to content

Commit

Permalink
Merge pull request #897 from globus/fix-groups-api
Browse files Browse the repository at this point in the history
Allow copied-and-pasted API routes to the `globus api groups` command
  • Loading branch information
kurtmckee authored Nov 28, 2023
2 parents 8ea4ab0 + 507838c commit c6bff0b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20231128_151455_kurtmckee_fix_groups_api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Bugfixes

* Accommodate copied-and-pasted API routes to the `globus api groups` command
that include the `/v2` route.
5 changes: 5 additions & 0 deletions src/globus_cli/commands/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ def service_command(
# the overall flow of this command will be as follows:
# - prepare a client
# - prepare parameters for the request
# - Groups-only - strip copied-and-pasted paths with `/v2/` that will fail
# - send the request capturing any error raised
# - process the response
# - on success or error with --allow-errors, print
Expand Down Expand Up @@ -300,6 +301,10 @@ def service_command(
for header_name, header_value in header:
headers_d[header_name] = header_value

# Strip `/v2` from Groups paths, which are auto-added by `GroupsClient`.
if service_name == "groups" and path.startswith("/v2"):
path = path[3:]

# try sending and handle any error
try:
res = client.request(
Expand Down
14 changes: 14 additions & 0 deletions tests/functional/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ def test_api_command_get(run_line, service_name, is_error_response):
assert result.output == '{"foo": "bar"}\n'


def test_api_groups_v2_path_stripping(run_line):
load_response(
RegisteredResponse(
service="groups",
status=200,
path="/foo",
json={"foo": "bar"},
)
)

result = run_line(["globus", "api", "groups", "get", "/v2/foo"])
assert result.output == '{"foo": "bar"}\n'


def test_api_command_can_use_jmespath(run_line):
load_response("cli.api.transfer_stub")

Expand Down

0 comments on commit c6bff0b

Please sign in to comment.