-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathimage_share_group.py
More file actions
142 lines (110 loc) · 5.07 KB
/
image_share_group.py
File metadata and controls
142 lines (110 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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