feat: Share runs via Python SDK#667
Open
dima-aignostics wants to merge 15 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to add “run sharing” capabilities to the Python SDK by introducing access-control resource wrappers (grants + share tokens), wiring them into the platform client, and exposing sharing workflows through the application service and CLI.
Changes:
- Added new access-control resource layer (
AccessGrant,ShareToken,ShareTokens) and newRunhelpers (list_share_grants,grant_access). - Added new application service + CLI commands under
run share ...to list/grant/revoke access and manage share tokens. - Regenerated codegen artifacts/docs for updated API parameters (e.g., grants relation filter, additional run filters, run organization_id field).
Reviewed changes
Copilot reviewed 8 out of 61 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
src/aignostics/platform/resources/access.py |
New access-control resource models and share-token listing/creation logic. |
src/aignostics/platform/resources/runs.py |
Adds run-level grant listing/creation helpers with caching/retry integration. |
src/aignostics/platform/_client.py |
Exposes a share_tokens resource on Client. |
src/aignostics/application/_service.py |
Adds service methods for run sharing and token management. |
src/aignostics/application/_cli.py |
Adds run share ... CLI command group. |
tests/aignostics/platform/resources/access_test.py |
Unit tests for access resources. |
tests/aignostics/platform/resources/run_sharing_test.py |
Unit tests for run-sharing workflows (currently mismatched with implementation). |
codegen/in/openapi.json + codegen/out/** |
Codegen updates reflecting API spec changes. |
Codecov Report❌ Patch coverage is
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Wraps the create_grant API call in a Retrying block with exponential backoff and jitter, consistent with list_share_grants and other methods. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… grants - Add --expires-at option to `application run share token create` CLI command; accepts ISO 8601 string, defaults to UTC if no timezone given - Add expires_at parameter to Service.application_run_create_share_token() - Promote organization_id from --option to positional [ORGANIZATION_ID] argument in both `share organization grant` and `share organization revoke` commands - Add organization_id parameter to application_run_unshare_with_organization() so revoke filters grants by org (defaults to authenticated user's own org) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
3bbec8d to
1131c91
Compare
1131c91 to
fa0f3b9
Compare
fa0f3b9 to
c4e64be
Compare
- Add 34 integration tests covering all run share CLI subcommands
(status, org list/grant/revoke, token list/create/revoke) including
success, not-found, and error paths with both text and JSON output
- Add 15 unit tests for the 6 new service sharing methods
- Fix ShareTokens.list() cache key isolation bug: run_id was captured
from closure scope and not included in the @cached_operation key,
causing queries for different run IDs to share cache entries
- Fix --expires-at Z suffix parsing: remove unnecessary
.replace("Z", "+00:00") workaround since Python ≥ 3.11 handles the
Z UTC designator natively in datetime.fromisoformat()
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ffa17dc to
ece8b91
Compare
- Fix extra space before colon in share-with-organization error message - Fix docstring for application_run_revoke_share_token: NotFoundException is raised when the share token is not found, not the run - Fix run_share_token_revoke CLI handler to print the exception message instead of a hardcoded "Run ... not found" string, so users see the correct context (token ID not found vs run ID not found) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
application_run_revoke_share_token now finds the SHARE_TOKEN grant on the specific run and revokes that grant, leaving the token itself intact for any other runs it may be shared with. Raises NotFoundException when no grant for the token exists on the run. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
GrantReadResponse carries these three fields but AccessGrant was silently dropping them. Adding them lets callers (e.g. ShareToken. list_share_grants()) inspect which resource a grant applies to and who created it, without having to go back to the raw codegen model. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Comment on lines
+262
to
+286
| def list_share_grants(self, *, page_size: int = 100) -> Iterator[AccessGrant]: | ||
| """List all active grants where this token is the subject. | ||
|
|
||
| Each returned ``AccessGrant`` represents a resource this token has been | ||
| granted access to. Call ``grant.revoke()`` to remove access to a | ||
| specific resource without invalidating the token itself. | ||
|
|
||
| Args: | ||
| page_size: Number of grants to fetch per page (max 100). | ||
|
|
||
| Returns: | ||
| Iterator of ``AccessGrant`` objects for this token. | ||
|
|
||
| Raises: | ||
| Exception: If the API request fails. | ||
|
|
||
| Example:: | ||
|
|
||
| token = client.share_tokens.create() | ||
| for grant in token.list_share_grants(): | ||
| print(grant.grant_id, grant.relation) | ||
| """ | ||
|
|
||
| def fetch_page(**kwargs: object) -> list[GrantReadResponse]: | ||
| return cast( |
Comment on lines
+347
to
+380
| def list(self, *, run_id: str | None = None, nocache: bool = False, page_size: int = 100) -> Iterator[ShareToken]: | ||
| """List all share tokens for the authenticated user. | ||
|
|
||
| Results are cached for ``run_cache_ttl`` seconds and retried on | ||
| transient network or server errors. | ||
|
|
||
| Args: | ||
| run_id: Optional run ID to filter tokens by the run they are associated with. | ||
| Defaults to ``None`` (no filter). | ||
| nocache: If ``True``, bypass the local cache and fetch fresh data | ||
| from the API. The fetched result is still written to the cache. | ||
| Defaults to ``False``. | ||
| page_size: Number of tokens to fetch per page (max 100). | ||
| Defaults to 100. | ||
|
|
||
| Returns: | ||
| Iterator of ``ShareToken`` objects. | ||
|
|
||
| Raises: | ||
| Exception: If the API request fails after all retries. | ||
|
|
||
| Example:: | ||
|
|
||
| for token in client.share_tokens.list(): | ||
| print(token.share_token_id, token.revoked) | ||
|
|
||
| # Force a fresh fetch after creating a new token | ||
| for token in client.share_tokens.list(nocache=True): | ||
| print(token.share_token_id) | ||
| """ | ||
|
|
||
| @cached_operation(ttl=settings().run_cache_ttl, token_provider=self._api.token_provider) | ||
| def list_data_with_retry(cached_run_id: str | None, **kwargs: object) -> builtins.list[ShareToken]: | ||
| return Retrying( |
Comment on lines
4344
to
4351
| "OAuth2AuthorizationCodeBearer": { | ||
| "type": "oauth2", | ||
| "flows": { | ||
| "authorizationCode": { | ||
| "scopes": {}, | ||
| "authorizationUrl": "https://aignostics-platform-staging.eu.auth0.com/authorize", | ||
| "tokenUrl": "https://aignostics-platform-staging.eu.auth0.com/oauth/token" | ||
| "authorizationUrl": "https://dev-8ouohmmrbuh2h4vu.eu.auth0.com/authorize", | ||
| "tokenUrl": "https://dev-8ouohmmrbuh2h4vu.eu.auth0.com/oauth/token" | ||
| } |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



No description provided.