1 package workspaces
2
3
4
5
6
7
8
9 import (
10 "context"
11 "encoding/json"
12 "github.com/Azure/go-autorest/autorest"
13 "github.com/Azure/go-autorest/autorest/to"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19 const fqdn = "github.com/Azure/azure-sdk-for-go/services/machinelearning/mgmt/2016-04-01/workspaces"
20
21
22 type ErrorResponse struct {
23
24 Code *string `json:"code,omitempty"`
25
26 Message *string `json:"message,omitempty"`
27 }
28
29
30 type KeysResponse struct {
31 autorest.Response `json:"-"`
32
33 PrimaryToken *string `json:"primaryToken,omitempty"`
34
35 SecondaryToken *string `json:"secondaryToken,omitempty"`
36 }
37
38
39 type ListResult struct {
40 autorest.Response `json:"-"`
41
42 Value *[]Workspace `json:"value,omitempty"`
43
44 NextLink *string `json:"nextLink,omitempty"`
45 }
46
47
48 type ListResultIterator struct {
49 i int
50 page ListResultPage
51 }
52
53
54
55 func (iter *ListResultIterator) NextWithContext(ctx context.Context) (err error) {
56 if tracing.IsEnabled() {
57 ctx = tracing.StartSpan(ctx, fqdn+"/ListResultIterator.NextWithContext")
58 defer func() {
59 sc := -1
60 if iter.Response().Response.Response != nil {
61 sc = iter.Response().Response.Response.StatusCode
62 }
63 tracing.EndSpan(ctx, sc, err)
64 }()
65 }
66 iter.i++
67 if iter.i < len(iter.page.Values()) {
68 return nil
69 }
70 err = iter.page.NextWithContext(ctx)
71 if err != nil {
72 iter.i--
73 return err
74 }
75 iter.i = 0
76 return nil
77 }
78
79
80
81
82 func (iter *ListResultIterator) Next() error {
83 return iter.NextWithContext(context.Background())
84 }
85
86
87 func (iter ListResultIterator) NotDone() bool {
88 return iter.page.NotDone() && iter.i < len(iter.page.Values())
89 }
90
91
92 func (iter ListResultIterator) Response() ListResult {
93 return iter.page.Response()
94 }
95
96
97
98 func (iter ListResultIterator) Value() Workspace {
99 if !iter.page.NotDone() {
100 return Workspace{}
101 }
102 return iter.page.Values()[iter.i]
103 }
104
105
106 func NewListResultIterator(page ListResultPage) ListResultIterator {
107 return ListResultIterator{page: page}
108 }
109
110
111 func (lr ListResult) IsEmpty() bool {
112 return lr.Value == nil || len(*lr.Value) == 0
113 }
114
115
116 func (lr ListResult) hasNextLink() bool {
117 return lr.NextLink != nil && len(*lr.NextLink) != 0
118 }
119
120
121
122 func (lr ListResult) listResultPreparer(ctx context.Context) (*http.Request, error) {
123 if !lr.hasNextLink() {
124 return nil, nil
125 }
126 return autorest.Prepare((&http.Request{}).WithContext(ctx),
127 autorest.AsJSON(),
128 autorest.AsGet(),
129 autorest.WithBaseURL(to.String(lr.NextLink)))
130 }
131
132
133 type ListResultPage struct {
134 fn func(context.Context, ListResult) (ListResult, error)
135 lr ListResult
136 }
137
138
139
140 func (page *ListResultPage) NextWithContext(ctx context.Context) (err error) {
141 if tracing.IsEnabled() {
142 ctx = tracing.StartSpan(ctx, fqdn+"/ListResultPage.NextWithContext")
143 defer func() {
144 sc := -1
145 if page.Response().Response.Response != nil {
146 sc = page.Response().Response.Response.StatusCode
147 }
148 tracing.EndSpan(ctx, sc, err)
149 }()
150 }
151 for {
152 next, err := page.fn(ctx, page.lr)
153 if err != nil {
154 return err
155 }
156 page.lr = next
157 if !next.hasNextLink() || !next.IsEmpty() {
158 break
159 }
160 }
161 return nil
162 }
163
164
165
166
167 func (page *ListResultPage) Next() error {
168 return page.NextWithContext(context.Background())
169 }
170
171
172 func (page ListResultPage) NotDone() bool {
173 return !page.lr.IsEmpty()
174 }
175
176
177 func (page ListResultPage) Response() ListResult {
178 return page.lr
179 }
180
181
182 func (page ListResultPage) Values() []Workspace {
183 if page.lr.IsEmpty() {
184 return nil
185 }
186 return *page.lr.Value
187 }
188
189
190 func NewListResultPage(cur ListResult, getNextPage func(context.Context, ListResult) (ListResult, error)) ListResultPage {
191 return ListResultPage{
192 fn: getNextPage,
193 lr: cur,
194 }
195 }
196
197
198 type Operation struct {
199
200 Name *string `json:"name,omitempty"`
201
202 Display *OperationDisplay `json:"display,omitempty"`
203 }
204
205
206 type OperationDisplay struct {
207
208 Provider *string `json:"provider,omitempty"`
209
210 Resource *string `json:"resource,omitempty"`
211
212 Operation *string `json:"operation,omitempty"`
213
214 Description *string `json:"description,omitempty"`
215 }
216
217
218 type OperationListResult struct {
219 autorest.Response `json:"-"`
220
221 Value *[]Operation `json:"value,omitempty"`
222 }
223
224
225 type Properties struct {
226
227 UserStorageAccountID *string `json:"userStorageAccountId,omitempty"`
228
229 OwnerEmail *string `json:"ownerEmail,omitempty"`
230
231 WorkspaceType WorkspaceType `json:"workspaceType,omitempty"`
232
233 WorkspaceState State `json:"workspaceState,omitempty"`
234
235 WorkspaceID *string `json:"workspaceId,omitempty"`
236
237 CreationTime *string `json:"creationTime,omitempty"`
238
239 StudioEndpoint *string `json:"studioEndpoint,omitempty"`
240
241 KeyVaultIdentifierID *string `json:"keyVaultIdentifierId,omitempty"`
242 }
243
244
245 func (p Properties) MarshalJSON() ([]byte, error) {
246 objectMap := make(map[string]interface{})
247 if p.UserStorageAccountID != nil {
248 objectMap["userStorageAccountId"] = p.UserStorageAccountID
249 }
250 if p.OwnerEmail != nil {
251 objectMap["ownerEmail"] = p.OwnerEmail
252 }
253 if p.KeyVaultIdentifierID != nil {
254 objectMap["keyVaultIdentifierId"] = p.KeyVaultIdentifierID
255 }
256 return json.Marshal(objectMap)
257 }
258
259
260 type PropertiesUpdateParameters struct {
261
262 WorkspaceState State `json:"workspaceState,omitempty"`
263
264 KeyVaultIdentifierID *string `json:"keyVaultIdentifierId,omitempty"`
265 }
266
267
268 type Resource struct {
269
270 ID *string `json:"id,omitempty"`
271
272 Name *string `json:"name,omitempty"`
273
274 Type *string `json:"type,omitempty"`
275
276 Location *string `json:"location,omitempty"`
277
278 Tags map[string]*string `json:"tags"`
279 }
280
281
282 func (r Resource) MarshalJSON() ([]byte, error) {
283 objectMap := make(map[string]interface{})
284 if r.Location != nil {
285 objectMap["location"] = r.Location
286 }
287 if r.Tags != nil {
288 objectMap["tags"] = r.Tags
289 }
290 return json.Marshal(objectMap)
291 }
292
293
294 type UpdateParameters struct {
295
296 Tags map[string]*string `json:"tags"`
297
298 *PropertiesUpdateParameters `json:"properties,omitempty"`
299 }
300
301
302 func (up UpdateParameters) MarshalJSON() ([]byte, error) {
303 objectMap := make(map[string]interface{})
304 if up.Tags != nil {
305 objectMap["tags"] = up.Tags
306 }
307 if up.PropertiesUpdateParameters != nil {
308 objectMap["properties"] = up.PropertiesUpdateParameters
309 }
310 return json.Marshal(objectMap)
311 }
312
313
314 func (up *UpdateParameters) UnmarshalJSON(body []byte) error {
315 var m map[string]*json.RawMessage
316 err := json.Unmarshal(body, &m)
317 if err != nil {
318 return err
319 }
320 for k, v := range m {
321 switch k {
322 case "tags":
323 if v != nil {
324 var tags map[string]*string
325 err = json.Unmarshal(*v, &tags)
326 if err != nil {
327 return err
328 }
329 up.Tags = tags
330 }
331 case "properties":
332 if v != nil {
333 var propertiesUpdateParameters PropertiesUpdateParameters
334 err = json.Unmarshal(*v, &propertiesUpdateParameters)
335 if err != nil {
336 return err
337 }
338 up.PropertiesUpdateParameters = &propertiesUpdateParameters
339 }
340 }
341 }
342
343 return nil
344 }
345
346
347 type Workspace struct {
348 autorest.Response `json:"-"`
349
350 *Properties `json:"properties,omitempty"`
351
352 ID *string `json:"id,omitempty"`
353
354 Name *string `json:"name,omitempty"`
355
356 Type *string `json:"type,omitempty"`
357
358 Location *string `json:"location,omitempty"`
359
360 Tags map[string]*string `json:"tags"`
361 }
362
363
364 func (w Workspace) MarshalJSON() ([]byte, error) {
365 objectMap := make(map[string]interface{})
366 if w.Properties != nil {
367 objectMap["properties"] = w.Properties
368 }
369 if w.Location != nil {
370 objectMap["location"] = w.Location
371 }
372 if w.Tags != nil {
373 objectMap["tags"] = w.Tags
374 }
375 return json.Marshal(objectMap)
376 }
377
378
379 func (w *Workspace) UnmarshalJSON(body []byte) error {
380 var m map[string]*json.RawMessage
381 err := json.Unmarshal(body, &m)
382 if err != nil {
383 return err
384 }
385 for k, v := range m {
386 switch k {
387 case "properties":
388 if v != nil {
389 var properties Properties
390 err = json.Unmarshal(*v, &properties)
391 if err != nil {
392 return err
393 }
394 w.Properties = &properties
395 }
396 case "id":
397 if v != nil {
398 var ID string
399 err = json.Unmarshal(*v, &ID)
400 if err != nil {
401 return err
402 }
403 w.ID = &ID
404 }
405 case "name":
406 if v != nil {
407 var name string
408 err = json.Unmarshal(*v, &name)
409 if err != nil {
410 return err
411 }
412 w.Name = &name
413 }
414 case "type":
415 if v != nil {
416 var typeVar string
417 err = json.Unmarshal(*v, &typeVar)
418 if err != nil {
419 return err
420 }
421 w.Type = &typeVar
422 }
423 case "location":
424 if v != nil {
425 var location string
426 err = json.Unmarshal(*v, &location)
427 if err != nil {
428 return err
429 }
430 w.Location = &location
431 }
432 case "tags":
433 if v != nil {
434 var tags map[string]*string
435 err = json.Unmarshal(*v, &tags)
436 if err != nil {
437 return err
438 }
439 w.Tags = tags
440 }
441 }
442 }
443
444 return nil
445 }
446
View as plain text