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

Add 'globus api' command #626

Merged
merged 6 commits into from
May 5, 2022
Merged

Add 'globus api' command #626

merged 6 commits into from
May 5, 2022

Conversation

sirosen
Copy link
Member

@sirosen sirosen commented Apr 8, 2022

Right now, this is just a "first cut", and needs a bit more work. However, I was able to use it to do a few Transfer calls and it seems okay.

This is lacking in testing, there's no detailed documentation, and several parameters need more docs.
In no particular order, these are the TODO items which I still have on this:

  • add --body-file, make it mutex with --body
  • update SDK upstream to fix annotations to allow data: str for request bodies
  • add tests for content-type detection
  • add a --header option with multiple=True
  • set app_name on clients in the api commands to "globus-cli-raw" + CLI version info
  • add some basic tests

Update: This is now ready for review.

It add globus api [transfer|auth|groups|search] [HEAD|GET|PUT|POST|DELETE] PATH, with options for setting headers and query params with some basic parsing.

Some specifics on Content-Type:
Because many Globus APIs expect or require a content-type when reading JSON data, it seemed worthwhile to add some special handling for it. Namely, there is some simple Content-Type detection which will treat json-parseable data as Content-Type: application/json, and this can be controlled or fine-tuned with --content-type. It is applied to the headers before --header values are parsed and handled, so that --header "Content-Type: application/octet-stream" works as desired/expected and overrides the autodetect behavior.

src/globus_cli/commands/api.py Outdated Show resolved Hide resolved
src/globus_cli/commands/api.py Show resolved Hide resolved
src/globus_cli/commands/api.py Show resolved Hide resolved
@sirosen sirosen marked this pull request as draft April 15, 2022 16:05
@sirosen
Copy link
Member Author

sirosen commented Apr 15, 2022

I've just pushed an intentionally-failing commit which I'll squash/amend later. It serves to explain some of the work I'm about to open in a PR against globus-sdk.

sirosen added 4 commits May 4, 2022 19:48
This is lacking in testing, but works under some simple example
usages. There's no detailed documentation and several parameters need
more docs.
- Support headers
- Improve content-type detection
- Add '--body-file' as mutex with '--body'
- Set "raw-api-command" in app_name on clients
- Improve --help output
`for x in ...` binds `x` dynamically inside the loop scope, and we
wanted to have a closure over `x`. An explicit function to act as a
closure avoids this sabotaging the `globus api` command.

This was discovered with the addition of a variety of unit tests and a
functional test for the `globus api` command.
Allow error responses to be rendered verbatim (without our handlers
running) if `--allow-errors` is used. Do not follow redirects unless
`--allow-redirects/--location/-L` is used.

The new attributes of response and error classes make it easy to
unify the printing logic such that errors and responses are printed in
the same way. The only difference between the two is the name of the
text body attribute.
@sirosen sirosen marked this pull request as ready for review May 4, 2022 19:53
sirosen added 2 commits May 4, 2022 20:40
`globus api` commands now allow a flag `--no-retry` to disable
automatic request retries.

The tests for `globus api` which use error responses now pass
`--no-retry`.
Instead of ": ", split on ":" and trim exactly one leading whitespace
if present. This behavior is probably simpler for users and can still
express any amount of whitespace in a header.
@sirosen sirosen merged commit f84834b into globus:main May 5, 2022
@sirosen sirosen deleted the api-cmd branch May 5, 2022 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant