-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathimage_sharegroups_producer.go
More file actions
346 lines (308 loc) · 10.8 KB
/
image_sharegroups_producer.go
File metadata and controls
346 lines (308 loc) · 10.8 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
package linodego
import (
"context"
"encoding/json"
"time"
"github.com/linode/linodego/internal/parseabletime"
)
// ProducerImageShareGroup represents an ImageShareGroup owned by the producer.
type ProducerImageShareGroup struct {
ID int `json:"id"`
UUID string `json:"uuid"`
Label string `json:"label"`
Description string `json:"description"`
IsSuspended bool `json:"is_suspended"`
ImagesCount int `json:"images_count"`
MembersCount int `json:"members_count"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
Expiry *time.Time `json:"-"`
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (isg *ProducerImageShareGroup) UnmarshalJSON(b []byte) error {
type Mask ProducerImageShareGroup
p := struct {
*Mask
Created *parseabletime.ParseableTime `json:"created"`
Updated *parseabletime.ParseableTime `json:"updated"`
Expiry *parseabletime.ParseableTime `json:"expiry"`
}{
Mask: (*Mask)(isg),
}
if err := json.Unmarshal(b, &p); err != nil {
return err
}
isg.Created = (*time.Time)(p.Created)
isg.Updated = (*time.Time)(p.Updated)
isg.Expiry = (*time.Time)(p.Expiry)
return nil
}
// ImageShareGroupCreateOptions fields are those accepted by CreateImageShareGroup.
type ImageShareGroupCreateOptions struct {
Label string `json:"label"`
Description *string `json:"description,omitempty"`
Images []ImageShareGroupImage `json:"images,omitempty"`
}
// ImageShareGroupUpdateOptions fields are those accepted by UpdateImageShareGroup.
type ImageShareGroupUpdateOptions struct {
Label *string `json:"label,omitempty"`
Description *string `json:"description,omitempty"`
}
// ImageShareGroupAddImagesOptions fields are those accepted by ImageShareGroupAddImages.
type ImageShareGroupAddImagesOptions struct {
Images []ImageShareGroupImage `json:"images"`
}
// ImageShareGroupUpdateImageOptions fields are those accepted by ImageShareGroupUpdateImage.
type ImageShareGroupUpdateImageOptions struct {
Label *string `json:"label,omitempty"`
Description *string `json:"description,omitempty"`
}
// ImageShareGroupImage represents an Image to be included in a ProducerImageShareGroup.
type ImageShareGroupImage struct {
ID string `json:"id"`
Label *string `json:"label,omitempty"`
Description *string `json:"description,omitempty"`
}
// ImageShareGroupMember represents a Member of an ImageShareGroup owned by the producer.
type ImageShareGroupMember struct {
TokenUUID string `json:"token_uuid"`
Status string `json:"status"`
Label string `json:"label"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
Expiry *time.Time `json:"-"`
}
// ImageShareGroupUpdateMemberOptions fields are those accepted by ImageShareGroupUpdateMember.
type ImageShareGroupUpdateMemberOptions struct {
Label string `json:"label"`
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (m *ImageShareGroupMember) UnmarshalJSON(b []byte) error {
type Mask ImageShareGroupMember
p := struct {
*Mask
Created *parseabletime.ParseableTime `json:"created"`
Updated *parseabletime.ParseableTime `json:"updated"`
Expiry *parseabletime.ParseableTime `json:"expiry"`
}{
Mask: (*Mask)(m),
}
if err := json.Unmarshal(b, &p); err != nil {
return err
}
m.Created = (*time.Time)(p.Created)
m.Updated = (*time.Time)(p.Updated)
m.Expiry = (*time.Time)(p.Expiry)
return nil
}
// ImageShareGroupAddMemberOptions fields are those accepted by ImageShareGroupAddMember.
// The token must be provided to the producer by the consumer via an outside medium.
type ImageShareGroupAddMemberOptions struct {
Token string `json:"token"`
Label string `json:"label"`
}
// ListImageShareGroups lists all ImageShareGroups owned by the producer.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ListImageShareGroups(
ctx context.Context,
opts *ListOptions,
) ([]ProducerImageShareGroup, error) {
return getPaginatedResults[ProducerImageShareGroup](
ctx,
c,
"images/sharegroups",
opts,
)
}
// ListImageShareGroupsContainingPrivateImage lists all current ImageShareGroups owned by the producer where
// the given private image is present.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ListImageShareGroupsContainingPrivateImage(
ctx context.Context,
privateImageID string,
opts *ListOptions,
) ([]ProducerImageShareGroup, error) {
return getPaginatedResults[ProducerImageShareGroup](
ctx,
c,
formatAPIPath("images/%s/sharegroups", privateImageID),
opts,
)
}
// GetImageShareGroup gets the specified ImageShareGroup owned by the producer.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) GetImageShareGroup(
ctx context.Context,
imageShareGroupID int,
) (*ProducerImageShareGroup, error) {
return doGETRequest[ProducerImageShareGroup](
ctx,
c,
formatAPIPath("images/sharegroups/%d", imageShareGroupID),
)
}
// CreateImageShareGroup allows the producer to create a new ImageShareGroup.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) CreateImageShareGroup(
ctx context.Context,
opts ImageShareGroupCreateOptions,
) (*ProducerImageShareGroup, error) {
return doPOSTRequest[ProducerImageShareGroup](
ctx,
c,
"images/sharegroups",
opts,
)
}
// UpdateImageShareGroup allows the producer to update an existing ImageShareGroup's description and label.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) UpdateImageShareGroup(
ctx context.Context,
imageShareGroupID int,
opts ImageShareGroupUpdateOptions,
) (*ProducerImageShareGroup, error) {
return doPUTRequest[ProducerImageShareGroup](
ctx,
c,
formatAPIPath("images/sharegroups/%d", imageShareGroupID),
opts,
)
}
// DeleteImageShareGroup deletes the specified ImageShareGroup owned by the producer.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) DeleteImageShareGroup(ctx context.Context, imageShareGroupID int) error {
return doDELETERequest(
ctx,
c,
formatAPIPath("images/sharegroups/%d", imageShareGroupID),
)
}
// ImageShareGroupListImageShareEntries lists the shared image entries of a specified ImageShareGroup owned by the producer.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupListImageShareEntries(
ctx context.Context,
imageShareGroupID int,
opts *ListOptions,
) ([]ImageShareEntry, error) {
return getPaginatedResults[ImageShareEntry](
ctx,
c,
formatAPIPath("images/sharegroups/%d/images", imageShareGroupID),
opts,
)
}
// ImageShareGroupAddImages allows the producer to add images to a specific ImageShareGroup.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupAddImages(
ctx context.Context,
imageShareGroupID int,
opts ImageShareGroupAddImagesOptions,
) ([]ImageShareEntry, error) {
return postPaginatedResults[ImageShareEntry, ImageShareGroupAddImagesOptions](
ctx,
c,
formatAPIPath("images/sharegroups/%d/images", imageShareGroupID),
nil,
opts,
)
}
// ImageShareGroupUpdateImageShareEntry allows the producer to update the description and label of a specified ImageShareEntry within the specified ImageShareGroup.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupUpdateImageShareEntry(
ctx context.Context,
imageShareGroupID int,
imageID string,
opts ImageShareGroupUpdateImageOptions,
) (*ImageShareEntry, error) {
return doPUTRequest[ImageShareEntry](
ctx,
c,
formatAPIPath("images/sharegroups/%d/images/%s", imageShareGroupID, imageID),
opts,
)
}
// ImageShareGroupRemoveImage allows the producer to remove access to an image within an ImageShareGroup owned by the producer.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupRemoveImage(
ctx context.Context,
imageShareGroupID int,
imageID string,
) error {
return doDELETERequest(
ctx,
c,
formatAPIPath("images/sharegroups/%d/images/%s", imageShareGroupID, imageID),
)
}
// ImageShareGroupListMembers lists the ImageShareGroupMembers of the provided ImageShareGroup owned by the producer.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupListMembers(
ctx context.Context,
imageShareGroupID int,
opts *ListOptions,
) ([]ImageShareGroupMember, error) {
return getPaginatedResults[ImageShareGroupMember](
ctx,
c,
formatAPIPath("images/sharegroups/%d/members", imageShareGroupID),
opts,
)
}
// ImageShareGroupGetMember gets the details of the specified ImageShareGroupMember in the specified
// ImageShareGroup owned by the producer.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupGetMember(
ctx context.Context,
imageShareGroupID int,
tokenUUID string,
) (*ImageShareGroupMember, error) {
return doGETRequest[ImageShareGroupMember](
ctx,
c,
formatAPIPath("images/sharegroups/%d/members/%s", imageShareGroupID, tokenUUID),
)
}
// ImageShareGroupAddMember allows the producer to add members to a specific ImageShareGroup.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupAddMember(
ctx context.Context,
imageShareGroupID int,
opts ImageShareGroupAddMemberOptions,
) (*ImageShareGroupMember, error) {
return doPOSTRequest[ImageShareGroupMember](
ctx,
c,
formatAPIPath("images/sharegroups/%d/members", imageShareGroupID),
opts,
)
}
// ImageShareGroupUpdateMember allows the producer to update the label associated with the specified
// ImageShareGroupMember in the specified ImageShareGroup owned by the producer.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupUpdateMember(
ctx context.Context,
imageShareGroupID int,
tokenUUID string,
opts ImageShareGroupUpdateMemberOptions,
) (*ImageShareGroupMember, error) {
return doPUTRequest[ImageShareGroupMember](
ctx,
c,
formatAPIPath("images/sharegroups/%d/members/%s", imageShareGroupID, tokenUUID),
opts,
)
}
// ImageShareGroupRemoveMember allows the producer to remove an individual ImageShareGroupMember
// that’s been accepted into the ImageShareGroup owned by the producer.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupRemoveMember(
ctx context.Context,
imageShareGroupID int,
tokenUUID string,
) error {
return doDELETERequest(
ctx,
c,
formatAPIPath("images/sharegroups/%d/members/%s", imageShareGroupID, tokenUUID),
)
}