-
Notifications
You must be signed in to change notification settings - Fork 78
Added support for Private Image Sharing #623
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
ezilber-akamai
wants to merge
1
commit into
linode:proj/private-image-sharing
Choose a base branch
from
ezilber-akamai:TPT-3820-private-image-sharing
base: proj/private-image-sharing
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,142 @@ | ||
| from typing import Optional | ||
|
|
||
| from linode_api4.groups import Group | ||
| from linode_api4.objects import ( | ||
| ImageShareGroup, | ||
| ImageShareGroupImagesToAdd, | ||
| ImageShareGroupToken, | ||
| ) | ||
| from linode_api4.objects.base import _flatten_request_body_recursive | ||
| from linode_api4.util import drop_null_keys | ||
|
|
||
|
|
||
| class ImageShareGroupAPIGroup(Group): | ||
| """ | ||
| Collections related to Private Image Sharing. | ||
|
|
||
| NOTE: Private Image Sharing features are in beta and may not be generally available. | ||
| """ | ||
|
|
||
| def __call__(self, *filters): | ||
| """ | ||
| Retrieves a list of Image Share Groups created by the user (producer). | ||
| You can filter this query to retrieve only Image Share Groups | ||
| relevant to a specific query, for example:: | ||
|
|
||
| filtered_share_groups = client.sharegroups( | ||
| ImageShareGroup.label == "my-label") | ||
|
|
||
| API Documentation: https://techdocs.akamai.com/linode-api/reference/get-sharegroups | ||
|
|
||
| :param filters: Any number of filters to apply to this query. | ||
| See :doc:`Filtering Collections</linode_api4/objects/filtering>` | ||
| for more details on filtering. | ||
|
|
||
| :returns: A list of Image Share Groups. | ||
| :rtype: PaginatedList of ImageShareGroup | ||
| """ | ||
| return self.client._get_and_filter(ImageShareGroup, *filters) | ||
|
|
||
| def sharegroups_by_image_id(self, image_id: str): | ||
| """ | ||
| Retrieves a list of Image Share Groups that share a specific Private Image. | ||
|
|
||
| API Documentation: https://techdocs.akamai.com/linode-api/reference/get-images-sharegroups-image | ||
|
|
||
| :param image_id: The ID of the Image to query for. | ||
| :type image_id: str | ||
|
|
||
| :returns: A list of Image Share Groups sharing the specified Image. | ||
| :rtype: PaginatedList of ImageShareGroup | ||
| """ | ||
| return self.client._get_and_filter( | ||
| ImageShareGroup, endpoint="/images/{}/sharegroups".format(image_id) | ||
| ) | ||
|
|
||
| def tokens(self, *filters): | ||
| """ | ||
| Retrieves a list of Image Share Group Tokens created by the user (consumer). | ||
| You can filter this query to retrieve only Image Share Group Tokens | ||
| relevant to a specific query, for example:: | ||
|
|
||
| filtered_share_group_tokens = client.sharegroups.tokens( | ||
| ImageShareGroupToken.label == "my-label") | ||
|
|
||
| API Documentation: https://techdocs.akamai.com/linode-api/reference/get-user-tokens | ||
|
|
||
| :param filters: Any number of filters to apply to this query. | ||
| See :doc:`Filtering Collections</linode_api4/objects/filtering>` | ||
| for more details on filtering. | ||
|
|
||
| :returns: A list of Image Share Group Tokens. | ||
| :rtype: PaginatedList of ImageShareGroupToken | ||
| """ | ||
| return self.client._get_and_filter(ImageShareGroupToken, *filters) | ||
|
|
||
| def create_sharegroup( | ||
| self, | ||
| label: Optional[str] = None, | ||
| description: Optional[str] = None, | ||
| images: Optional[ImageShareGroupImagesToAdd] = None, | ||
| ): | ||
| """ | ||
| Creates a new Image Share Group. | ||
|
|
||
| API Documentation: https://techdocs.akamai.com/linode-api/reference/post-sharegroups | ||
|
|
||
| :param label: The label for the resulting Image Share Group. | ||
| :type label: str | ||
| :param description: The description for the new Image Share Group. | ||
| :type description: str | ||
| :param images: A list of Images to share in the new Image Share Group, formatted in JSON. | ||
| :type images: Optional[ImageShareGroupImagesToAdd] | ||
|
|
||
| :returns: The new Image Share Group. | ||
| :rtype: ImageShareGroup | ||
| """ | ||
| params = { | ||
| "label": label, | ||
| "description": description, | ||
| } | ||
|
|
||
| if images: | ||
| params["images"] = images | ||
|
|
||
| result = self.client.post( | ||
| "/images/sharegroups", | ||
| data=_flatten_request_body_recursive(drop_null_keys(params)), | ||
| ) | ||
|
|
||
| return ImageShareGroup(self.client, result["id"], result) | ||
|
|
||
| def create_token( | ||
| self, valid_for_sharegroup_uuid: str, label: Optional[str] = None | ||
| ): | ||
| """ | ||
| Creates a new Image Share Group Token and returns the token value. | ||
|
|
||
| API Documentation: https://techdocs.akamai.com/linode-api/reference/post-sharegroup-tokens | ||
|
|
||
| :param valid_for_sharegroup_uuid: The UUID of the Image Share Group that this token will be valid for. | ||
| :type valid_for_sharegroup_uuid: Optional[str] | ||
| :param label: The label for the resulting Image Share Group Token. | ||
| :type label: str | ||
|
|
||
| :returns: The new Image Share Group Token object and the one-time use token itself. | ||
| :rtype: (ImageShareGroupToken, str) | ||
| """ | ||
| params = {"valid_for_sharegroup_uuid": valid_for_sharegroup_uuid} | ||
|
|
||
| if label: | ||
| params["label"] = label | ||
|
|
||
| result = self.client.post( | ||
| "/images/sharegroups/tokens", | ||
| data=_flatten_request_body_recursive(drop_null_keys(params)), | ||
| ) | ||
|
|
||
| token_value = result.pop("token", None) | ||
| token_obj = ImageShareGroupToken( | ||
| self.client, result["token_uuid"], result | ||
| ) | ||
| return token_obj, token_value |
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
Oops, something went wrong.
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.