-
Notifications
You must be signed in to change notification settings - Fork 0
MPT-19908: add /integration/installations service #281
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
Open
albertsola
wants to merge
2
commits into
main
Choose a base branch
from
MPT-19908/integration-installations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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,69 @@ | ||
| from mpt_api_client.http import AsyncService, Service | ||
| from mpt_api_client.http.mixins import ( | ||
| AsyncCollectionMixin, | ||
| AsyncManagedResourceMixin, | ||
| CollectionMixin, | ||
| ManagedResourceMixin, | ||
| ) | ||
| from mpt_api_client.models import Model | ||
| from mpt_api_client.models.model import BaseModel | ||
| from mpt_api_client.resources.integration.mixins import ( | ||
| AsyncInstallationMixin, | ||
| InstallationMixin, | ||
| ) | ||
|
|
||
|
|
||
| class Installation(Model): | ||
| """Installation resource. | ||
|
|
||
| Attributes: | ||
| name: Installation name. | ||
| revision: Revision number. | ||
| account: Reference to the account. | ||
| extension: Reference to the extension. | ||
| status: Installation status (Invited, Installed, Uninstalled, Expired). | ||
| configuration: Installation configuration data. | ||
| invitation: Invitation details. | ||
| modules: Modules included in the installation. | ||
| terms: Accepted terms for this installation. | ||
| audit: Audit information (created, updated, invited, installed, expired, uninstalled). | ||
| """ | ||
|
|
||
| name: str | None | ||
| revision: int | None | ||
| account: BaseModel | None | ||
| extension: BaseModel | None | ||
| status: str | None | ||
| configuration: BaseModel | None | ||
| invitation: BaseModel | None | ||
| modules: list[BaseModel] | None | ||
| terms: list[BaseModel] | None | ||
| audit: BaseModel | None | ||
|
|
||
|
|
||
| class InstallationsServiceConfig: | ||
| """Installations service configuration.""" | ||
|
|
||
| _endpoint = "/public/v1/integration/installations" | ||
| _model_class = Installation | ||
| _collection_key = "data" | ||
|
|
||
|
|
||
| class InstallationsService( | ||
| InstallationMixin[Installation], | ||
| ManagedResourceMixin[Installation], | ||
| CollectionMixin[Installation], | ||
| Service[Installation], | ||
| InstallationsServiceConfig, | ||
| ): | ||
| """Sync service for the /public/v1/integration/installations endpoint.""" | ||
|
|
||
|
|
||
| class AsyncInstallationsService( | ||
| AsyncInstallationMixin[Installation], | ||
| AsyncManagedResourceMixin[Installation], | ||
| AsyncCollectionMixin[Installation], | ||
| AsyncService[Installation], | ||
| InstallationsServiceConfig, | ||
| ): | ||
| """Async service for the /public/v1/integration/installations endpoint.""" |
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
103 changes: 103 additions & 0 deletions
103
mpt_api_client/resources/integration/mixins/installation_mixin.py
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,103 @@ | ||
| from mpt_api_client.models import ResourceData | ||
|
|
||
|
|
||
| class InstallationMixin[Model]: | ||
| """Mixin that adds installation actions: redeem, renew, and token retrieval.""" | ||
|
|
||
| def redeem(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: | ||
| """Redeem an installation invitation. | ||
|
|
||
| Args: | ||
| resource_id: Installation ID. | ||
| resource_data: Redeem payload, for example ``{"code": "...", "modules": [...]}``. | ||
|
|
||
| Returns: | ||
| Updated installation. | ||
| """ | ||
| return self._resource(resource_id).post("redeem", json=resource_data) # type: ignore[attr-defined, no-any-return] | ||
|
|
||
| def renew(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: | ||
| """Renew an installation. | ||
|
|
||
| Args: | ||
| resource_id: Installation ID. | ||
| resource_data: Optional request body. | ||
|
|
||
| Returns: | ||
| Updated installation. | ||
| """ | ||
| return self._resource(resource_id).post("renew", json=resource_data) # type: ignore[attr-defined, no-any-return] | ||
|
|
||
| def token(self, resource_id: str) -> Model: | ||
| """Retrieve an access token for a specific installation. | ||
|
|
||
| Args: | ||
| resource_id: Installation ID. | ||
|
|
||
| Returns: | ||
| Token response. | ||
| """ | ||
| return self._resource(resource_id).post("token") # type: ignore[attr-defined, no-any-return] | ||
|
|
||
| def token_for_account(self, account_id: str | None = None) -> Model: | ||
| """Retrieve an installation token for an account. | ||
|
|
||
| Args: | ||
| account_id: Optional account ID sent as ``account.id`` query parameter. | ||
|
|
||
| Returns: | ||
| Token response. | ||
| """ | ||
| query_params = {"account.id": account_id} if account_id else None | ||
| return self._resource("-").post("token", query_params=query_params) # type: ignore[attr-defined, no-any-return] | ||
|
|
||
|
|
||
| class AsyncInstallationMixin[Model]: | ||
| """Async mixin for installation actions: redeem, renew, and token retrieval.""" | ||
|
|
||
| async def redeem(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: | ||
| """Redeem an installation invitation. | ||
|
|
||
| Args: | ||
| resource_id: Installation ID. | ||
| resource_data: Redeem payload, for example ``{"code": "...", "modules": [...]}``. | ||
|
|
||
| Returns: | ||
| Updated installation. | ||
| """ | ||
| return await self._resource(resource_id).post("redeem", json=resource_data) # type: ignore[attr-defined, no-any-return] | ||
|
|
||
| async def renew(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: | ||
| """Renew an installation. | ||
|
|
||
| Args: | ||
| resource_id: Installation ID. | ||
| resource_data: Optional request body. | ||
|
|
||
| Returns: | ||
| Updated installation. | ||
| """ | ||
| return await self._resource(resource_id).post("renew", json=resource_data) # type: ignore[attr-defined, no-any-return] | ||
|
|
||
| async def token(self, resource_id: str) -> Model: | ||
| """Retrieve an access token for a specific installation. | ||
|
|
||
| Args: | ||
| resource_id: Installation ID. | ||
|
|
||
| Returns: | ||
| Token response. | ||
| """ | ||
| return await self._resource(resource_id).post("token") # type: ignore[attr-defined, no-any-return] | ||
|
|
||
| async def token_for_account(self, account_id: str | None = None) -> Model: | ||
| """Retrieve an installation token for an account. | ||
|
|
||
| Args: | ||
| account_id: Optional account ID sent as ``account.id`` query parameter. | ||
|
|
||
| Returns: | ||
| Token response. | ||
| """ | ||
| query_params = {"account.id": account_id} if account_id else None | ||
| return await self._resource("-").post("token", query_params=query_params) # type: ignore[attr-defined, no-any-return] |
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,6 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def extension_id(e2e_config): | ||
| return e2e_config["integration.extension.id"] |
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
Empty file.
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.