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/2019-10-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 Sku *Sku `json:"sku,omitempty"`
267 }
268
269
270 type Resource struct {
271
272 ID *string `json:"id,omitempty"`
273
274 Name *string `json:"name,omitempty"`
275
276 Type *string `json:"type,omitempty"`
277
278 Location *string `json:"location,omitempty"`
279
280 Tags map[string]*string `json:"tags"`
281
282 Sku *Sku `json:"sku,omitempty"`
283 }
284
285
286 func (r Resource) MarshalJSON() ([]byte, error) {
287 objectMap := make(map[string]interface{})
288 if r.Location != nil {
289 objectMap["location"] = r.Location
290 }
291 if r.Tags != nil {
292 objectMap["tags"] = r.Tags
293 }
294 if r.Sku != nil {
295 objectMap["sku"] = r.Sku
296 }
297 return json.Marshal(objectMap)
298 }
299
300
301 type Sku struct {
302
303 Name *string `json:"name,omitempty"`
304
305 Tier *string `json:"tier,omitempty"`
306 }
307
308
309 type UpdateParameters struct {
310
311 Tags map[string]*string `json:"tags"`
312
313 *PropertiesUpdateParameters `json:"properties,omitempty"`
314 }
315
316
317 func (up UpdateParameters) MarshalJSON() ([]byte, error) {
318 objectMap := make(map[string]interface{})
319 if up.Tags != nil {
320 objectMap["tags"] = up.Tags
321 }
322 if up.PropertiesUpdateParameters != nil {
323 objectMap["properties"] = up.PropertiesUpdateParameters
324 }
325 return json.Marshal(objectMap)
326 }
327
328
329 func (up *UpdateParameters) UnmarshalJSON(body []byte) error {
330 var m map[string]*json.RawMessage
331 err := json.Unmarshal(body, &m)
332 if err != nil {
333 return err
334 }
335 for k, v := range m {
336 switch k {
337 case "tags":
338 if v != nil {
339 var tags map[string]*string
340 err = json.Unmarshal(*v, &tags)
341 if err != nil {
342 return err
343 }
344 up.Tags = tags
345 }
346 case "properties":
347 if v != nil {
348 var propertiesUpdateParameters PropertiesUpdateParameters
349 err = json.Unmarshal(*v, &propertiesUpdateParameters)
350 if err != nil {
351 return err
352 }
353 up.PropertiesUpdateParameters = &propertiesUpdateParameters
354 }
355 }
356 }
357
358 return nil
359 }
360
361
362 type Workspace struct {
363 autorest.Response `json:"-"`
364
365 *Properties `json:"properties,omitempty"`
366
367 ID *string `json:"id,omitempty"`
368
369 Name *string `json:"name,omitempty"`
370
371 Type *string `json:"type,omitempty"`
372
373 Location *string `json:"location,omitempty"`
374
375 Tags map[string]*string `json:"tags"`
376
377 Sku *Sku `json:"sku,omitempty"`
378 }
379
380
381 func (w Workspace) MarshalJSON() ([]byte, error) {
382 objectMap := make(map[string]interface{})
383 if w.Properties != nil {
384 objectMap["properties"] = w.Properties
385 }
386 if w.Location != nil {
387 objectMap["location"] = w.Location
388 }
389 if w.Tags != nil {
390 objectMap["tags"] = w.Tags
391 }
392 if w.Sku != nil {
393 objectMap["sku"] = w.Sku
394 }
395 return json.Marshal(objectMap)
396 }
397
398
399 func (w *Workspace) UnmarshalJSON(body []byte) error {
400 var m map[string]*json.RawMessage
401 err := json.Unmarshal(body, &m)
402 if err != nil {
403 return err
404 }
405 for k, v := range m {
406 switch k {
407 case "properties":
408 if v != nil {
409 var properties Properties
410 err = json.Unmarshal(*v, &properties)
411 if err != nil {
412 return err
413 }
414 w.Properties = &properties
415 }
416 case "id":
417 if v != nil {
418 var ID string
419 err = json.Unmarshal(*v, &ID)
420 if err != nil {
421 return err
422 }
423 w.ID = &ID
424 }
425 case "name":
426 if v != nil {
427 var name string
428 err = json.Unmarshal(*v, &name)
429 if err != nil {
430 return err
431 }
432 w.Name = &name
433 }
434 case "type":
435 if v != nil {
436 var typeVar string
437 err = json.Unmarshal(*v, &typeVar)
438 if err != nil {
439 return err
440 }
441 w.Type = &typeVar
442 }
443 case "location":
444 if v != nil {
445 var location string
446 err = json.Unmarshal(*v, &location)
447 if err != nil {
448 return err
449 }
450 w.Location = &location
451 }
452 case "tags":
453 if v != nil {
454 var tags map[string]*string
455 err = json.Unmarshal(*v, &tags)
456 if err != nil {
457 return err
458 }
459 w.Tags = tags
460 }
461 case "sku":
462 if v != nil {
463 var sku Sku
464 err = json.Unmarshal(*v, &sku)
465 if err != nil {
466 return err
467 }
468 w.Sku = &sku
469 }
470 }
471 }
472
473 return nil
474 }
475
View as plain text