-
Notifications
You must be signed in to change notification settings - Fork 27
Added globus flows registered-api show command #1257
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4c7c757
Added globus flows registered-api show command
m1yag1 7b05918
fixup! Added globus flows registered-api show command
m1yag1 adca1d2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7e0d5ae
fixup! Added globus flows registered-api show command
m1yag1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelog.d/20260507_153740_8730430+m1yag1_sc_49699_add_gra_show_command.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### Enhancements | ||
|
|
||
| * Added `globus flows registered-api show` command to display details of a registered API |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from globus_cli.parsing import group | ||
|
|
||
|
|
||
| @group( | ||
| "registered-api", | ||
| lazy_subcommands={ | ||
| "show": (".show", "show_command"), | ||
| }, | ||
| ) | ||
| def registered_api_command() -> None: | ||
| """Interact with registered APIs in the Globus Flows service.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import uuid | ||
|
|
||
| import click | ||
|
|
||
| from globus_cli.commands.flows._fields import registered_api_format_fields | ||
| from globus_cli.login_manager import LoginManager | ||
| from globus_cli.parsing import command | ||
| from globus_cli.termio import display | ||
|
|
||
|
|
||
| @command("show") | ||
| @click.argument("registered_api_id", type=click.UUID) | ||
| @LoginManager.requires_login("auth", "flows") | ||
| def show_command(login_manager: LoginManager, *, registered_api_id: uuid.UUID) -> None: | ||
| """ | ||
| Show a registered API. | ||
| """ | ||
| flows_client = login_manager.get_flows_client() | ||
|
|
||
| res = flows_client.get_registered_api(registered_api_id) | ||
|
|
||
| auth_client = login_manager.get_auth_client() | ||
| fields = registered_api_format_fields(auth_client, res.data) | ||
|
|
||
| display(res, fields=fields, text_mode=display.RECORD) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import re | ||
|
|
||
| from globus_sdk.testing import load_response | ||
|
|
||
|
|
||
| def test_show_registered_api_text_output(run_line, load_identities_for_registered_api): | ||
| loaded_response = load_response("flows.get_registered_api") | ||
| response, meta = loaded_response.json, loaded_response.metadata | ||
|
|
||
| registered_api_id = meta["registered_api_id"] | ||
|
|
||
| pool = load_identities_for_registered_api(response) | ||
|
|
||
| result = run_line(f"globus flows registered-api show {registered_api_id}") | ||
|
|
||
| # all fields present | ||
| for fieldname in ( | ||
| "Registered API ID", | ||
| "Name", | ||
| "Description", | ||
| "Status", | ||
| "Subscription ID", | ||
| "Created At", | ||
| "Updated At", | ||
| "Owners", | ||
| "Administrators", | ||
| "Viewers", | ||
| "Target Type", | ||
| "OpenAPI Version", | ||
| "Destination Method", | ||
| "Destination URL", | ||
| ): | ||
| assert fieldname in result.output | ||
|
|
||
| # Verify principal resolution | ||
| roles = response.get("roles", {}) | ||
| assert_usernames(result, pool, "Owners", roles.get("owners", [])) | ||
| assert_usernames(result, pool, "Administrators", roles.get("administrators", [])) | ||
| assert_usernames(result, pool, "Viewers", roles.get("viewers", [])) | ||
|
|
||
|
|
||
| def assert_usernames(result, pool, field_name, principals): | ||
| expected_usernames = {pool.get_username(principal) for principal in principals} | ||
|
|
||
| output_value = _get_output_value(field_name, result.output) | ||
| output_usernames = {x.strip() for x in output_value.split(",")} | ||
| assert expected_usernames == output_usernames | ||
|
|
||
|
|
||
| def _get_output_value(name, output): | ||
| """ | ||
| Return the value for a specified field from the output of a command. | ||
| """ | ||
| match = re.search( | ||
| rf"^{re.escape(name)}:[^\S\n\r]+(?P<value>.*)$", output, flags=re.M | ||
| ) | ||
| assert match is not None | ||
| return match.group("value") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.