-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathimage_sharegroups_consumer.go
More file actions
215 lines (183 loc) · 7.43 KB
/
image_sharegroups_consumer.go
File metadata and controls
215 lines (183 loc) · 7.43 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
package linodego
import (
"context"
"encoding/json"
"time"
"github.com/linode/linodego/internal/parseabletime"
)
// ConsumerImageShareGroup represents an ImageShareGroup that the consumer is a member of.
type ConsumerImageShareGroup struct {
ID int `json:"id"`
UUID string `json:"uuid"`
Label string `json:"label"`
Description string `json:"description"`
IsSuspended bool `json:"is_suspended"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (isg *ConsumerImageShareGroup) UnmarshalJSON(b []byte) error {
type Mask ConsumerImageShareGroup
p := struct {
*Mask
Created *parseabletime.ParseableTime `json:"created"`
Updated *parseabletime.ParseableTime `json:"updated"`
}{
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)
return nil
}
// ImageShareGroupToken contains information about a token created by a consumer.
// The token itself is only visible once upon creation.
type ImageShareGroupToken struct {
TokenUUID string `json:"token_uuid"`
Status string `json:"status"`
Label string `json:"label"`
ValidForShareGroupUUID string `json:"valid_for_sharegroup_uuid"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
Expiry *time.Time `json:"-"`
ShareGroupUUID *string `json:"sharegroup_uuid"`
ShareGroupLabel *string `json:"sharegroup_label"`
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (t *ImageShareGroupToken) UnmarshalJSON(b []byte) error {
type Mask ImageShareGroupToken
p := struct {
*Mask
Created *parseabletime.ParseableTime `json:"created"`
Updated *parseabletime.ParseableTime `json:"updated"`
Expiry *parseabletime.ParseableTime `json:"expiry"`
}{
Mask: (*Mask)(t),
}
if err := json.Unmarshal(b, &p); err != nil {
return err
}
t.Created = (*time.Time)(p.Created)
t.Updated = (*time.Time)(p.Updated)
t.Expiry = (*time.Time)(p.Expiry)
return nil
}
// ImageShareGroupCreateTokenResponse represents the response when the consumer
// creates a single-use ImageShareGroup membership token.
// The token itself is only provided upon creation, and must be given to the producer
// via an outside medium for the consumer to be added as a member of the producer's ImageShareGroup.
type ImageShareGroupCreateTokenResponse struct {
Token string `json:"token"`
TokenUUID string `json:"token_uuid"`
Status string `json:"status"`
Label string `json:"label"`
ValidForShareGroupUUID string `json:"valid_for_sharegroup_uuid"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
Expiry *time.Time `json:"-"`
ShareGroupUUID *string `json:"sharegroup_uuid"`
ShareGroupLabel *string `json:"sharegroup_label"`
}
// UnmarshalJSON implements the json.Unmarshaler interface
func (t *ImageShareGroupCreateTokenResponse) UnmarshalJSON(b []byte) error {
type Mask ImageShareGroupCreateTokenResponse
p := struct {
*Mask
Created *parseabletime.ParseableTime `json:"created"`
Updated *parseabletime.ParseableTime `json:"updated"`
Expiry *parseabletime.ParseableTime `json:"expiry"`
}{
Mask: (*Mask)(t),
}
if err := json.Unmarshal(b, &p); err != nil {
return err
}
t.Created = (*time.Time)(p.Created)
t.Updated = (*time.Time)(p.Updated)
t.Expiry = (*time.Time)(p.Expiry)
return nil
}
// ImageShareGroupCreateTokenOptions fields are those accepted by ImageShareGroupCreateToken
type ImageShareGroupCreateTokenOptions struct {
Label *string `json:"label,omitempty"`
ValidForShareGroupUUID string `json:"valid_for_sharegroup_uuid"`
}
// ImageShareGroupUpdateTokenOptions fields are those accepted by ImageShareGroupUpdateToken
type ImageShareGroupUpdateTokenOptions struct {
Label string `json:"label"`
}
// ImageShareGroupListTokens lists information about all the ImageShareGroupTokens created by the user.
// The tokens themselves are only visible once upon creation.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupListTokens(ctx context.Context, opts *ListOptions) ([]ImageShareGroupToken, error) {
return getPaginatedResults[ImageShareGroupToken](
ctx,
c,
"images/sharegroups/tokens",
opts,
)
}
// ImageShareGroupGetToken gets information about the specified ImageShareGroupToken created by the user.
// The tokens themselves are only visible once upon creation.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupGetToken(ctx context.Context, tokenUUID string) (*ImageShareGroupToken, error) {
return doGETRequest[ImageShareGroupToken](
ctx,
c,
formatAPIPath("images/sharegroups/tokens/%s", tokenUUID),
)
}
// ImageShareGroupCreateToken allows the consumer to create a single-use ImageShareGroup membership
// token for a specific ImageShareGroup owned by the producer.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupCreateToken(ctx context.Context, opts ImageShareGroupCreateTokenOptions) (*ImageShareGroupCreateTokenResponse, error) {
return doPOSTRequest[ImageShareGroupCreateTokenResponse](
ctx,
c,
formatAPIPath("images/sharegroups/tokens"),
opts,
)
}
// ImageShareGroupUpdateToken allows the consumer to update an ImageShareGroupToken's label.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupUpdateToken(ctx context.Context, tokenUUID string, opts ImageShareGroupUpdateTokenOptions) (*ImageShareGroupToken, error) {
return doPUTRequest[ImageShareGroupToken](
ctx,
c,
formatAPIPath("images/sharegroups/tokens/%s", tokenUUID),
opts,
)
}
// ImageShareGroupRemoveToken allows the consumer to remove an individual ImageShareGroupToken from an ImageShareGroup
// this token has been accepted into.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupRemoveToken(ctx context.Context, tokenUUID string) error {
return doDELETERequest(
ctx,
c,
formatAPIPath("images/sharegroups/tokens/%s", tokenUUID),
)
}
// ImageShareGroupGetByToken gets information about the ImageShareGroup that the
// consumer's specified token has been accepted into.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupGetByToken(ctx context.Context, tokenUUID string) (*ConsumerImageShareGroup, error) {
return doGETRequest[ConsumerImageShareGroup](
ctx,
c,
formatAPIPath("images/sharegroups/tokens/%s/sharegroup", tokenUUID),
)
}
// ImageShareGroupGetImageShareEntriesByToken lists the shared image entries in the ImageShareGroup that the
// consumer's specified token has been accepted into.
// NOTE: May not currently be available to all users and can only be used with v4beta.
func (c *Client) ImageShareGroupGetImageShareEntriesByToken(ctx context.Context, tokenUUID string, opts *ListOptions) ([]ImageShareEntry, error) {
return getPaginatedResults[ImageShareEntry](
ctx,
c,
formatAPIPath("images/sharegroups/tokens/%s/sharegroup/images", tokenUUID),
opts,
)
}