1 package face
2
3
4
5
6
7
8
9 import (
10 "context"
11 "github.com/Azure/go-autorest/autorest"
12 "github.com/Azure/go-autorest/autorest/azure"
13 "github.com/Azure/go-autorest/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "github.com/gofrs/uuid"
16 "net/http"
17 )
18
19
20 type SnapshotClient struct {
21 BaseClient
22 }
23
24
25 func NewSnapshotClient(endpoint string) SnapshotClient {
26 return SnapshotClient{New(endpoint)}
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 func (client SnapshotClient) Apply(ctx context.Context, snapshotID uuid.UUID, body ApplySnapshotRequest) (result autorest.Response, err error) {
58 if tracing.IsEnabled() {
59 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Apply")
60 defer func() {
61 sc := -1
62 if result.Response != nil {
63 sc = result.Response.StatusCode
64 }
65 tracing.EndSpan(ctx, sc, err)
66 }()
67 }
68 if err := validation.Validate([]validation.Validation{
69 {TargetValue: body,
70 Constraints: []validation.Constraint{{Target: "body.ObjectID", Name: validation.Null, Rule: true,
71 Chain: []validation.Constraint{{Target: "body.ObjectID", Name: validation.MaxLength, Rule: 64, Chain: nil},
72 {Target: "body.ObjectID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil},
73 }}}}}); err != nil {
74 return result, validation.NewError("face.SnapshotClient", "Apply", err.Error())
75 }
76
77 req, err := client.ApplyPreparer(ctx, snapshotID, body)
78 if err != nil {
79 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Apply", nil, "Failure preparing request")
80 return
81 }
82
83 resp, err := client.ApplySender(req)
84 if err != nil {
85 result.Response = resp
86 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Apply", resp, "Failure sending request")
87 return
88 }
89
90 result, err = client.ApplyResponder(resp)
91 if err != nil {
92 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Apply", resp, "Failure responding to request")
93 return
94 }
95
96 return
97 }
98
99
100 func (client SnapshotClient) ApplyPreparer(ctx context.Context, snapshotID uuid.UUID, body ApplySnapshotRequest) (*http.Request, error) {
101 urlParameters := map[string]interface{}{
102 "Endpoint": client.Endpoint,
103 }
104
105 pathParameters := map[string]interface{}{
106 "snapshotId": autorest.Encode("path", snapshotID),
107 }
108
109 preparer := autorest.CreatePreparer(
110 autorest.AsContentType("application/json; charset=utf-8"),
111 autorest.AsPost(),
112 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
113 autorest.WithPathParameters("/snapshots/{snapshotId}/apply", pathParameters),
114 autorest.WithJSON(body))
115 return preparer.Prepare((&http.Request{}).WithContext(ctx))
116 }
117
118
119
120 func (client SnapshotClient) ApplySender(req *http.Request) (*http.Response, error) {
121 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
122 }
123
124
125
126 func (client SnapshotClient) ApplyResponder(resp *http.Response) (result autorest.Response, err error) {
127 err = autorest.Respond(
128 resp,
129 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
130 autorest.ByClosing())
131 result.Response = resp
132 return
133 }
134
135
136
137
138
139
140 func (client SnapshotClient) Delete(ctx context.Context, snapshotID uuid.UUID) (result autorest.Response, err error) {
141 if tracing.IsEnabled() {
142 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Delete")
143 defer func() {
144 sc := -1
145 if result.Response != nil {
146 sc = result.Response.StatusCode
147 }
148 tracing.EndSpan(ctx, sc, err)
149 }()
150 }
151 req, err := client.DeletePreparer(ctx, snapshotID)
152 if err != nil {
153 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Delete", nil, "Failure preparing request")
154 return
155 }
156
157 resp, err := client.DeleteSender(req)
158 if err != nil {
159 result.Response = resp
160 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Delete", resp, "Failure sending request")
161 return
162 }
163
164 result, err = client.DeleteResponder(resp)
165 if err != nil {
166 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Delete", resp, "Failure responding to request")
167 return
168 }
169
170 return
171 }
172
173
174 func (client SnapshotClient) DeletePreparer(ctx context.Context, snapshotID uuid.UUID) (*http.Request, error) {
175 urlParameters := map[string]interface{}{
176 "Endpoint": client.Endpoint,
177 }
178
179 pathParameters := map[string]interface{}{
180 "snapshotId": autorest.Encode("path", snapshotID),
181 }
182
183 preparer := autorest.CreatePreparer(
184 autorest.AsDelete(),
185 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
186 autorest.WithPathParameters("/snapshots/{snapshotId}", pathParameters))
187 return preparer.Prepare((&http.Request{}).WithContext(ctx))
188 }
189
190
191
192 func (client SnapshotClient) DeleteSender(req *http.Request) (*http.Response, error) {
193 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
194 }
195
196
197
198 func (client SnapshotClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
199 err = autorest.Respond(
200 resp,
201 azure.WithErrorUnlessStatusCode(http.StatusOK),
202 autorest.ByClosing())
203 result.Response = resp
204 return
205 }
206
207
208
209
210
211 func (client SnapshotClient) Get(ctx context.Context, snapshotID uuid.UUID) (result Snapshot, err error) {
212 if tracing.IsEnabled() {
213 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Get")
214 defer func() {
215 sc := -1
216 if result.Response.Response != nil {
217 sc = result.Response.Response.StatusCode
218 }
219 tracing.EndSpan(ctx, sc, err)
220 }()
221 }
222 req, err := client.GetPreparer(ctx, snapshotID)
223 if err != nil {
224 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Get", nil, "Failure preparing request")
225 return
226 }
227
228 resp, err := client.GetSender(req)
229 if err != nil {
230 result.Response = autorest.Response{Response: resp}
231 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Get", resp, "Failure sending request")
232 return
233 }
234
235 result, err = client.GetResponder(resp)
236 if err != nil {
237 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Get", resp, "Failure responding to request")
238 return
239 }
240
241 return
242 }
243
244
245 func (client SnapshotClient) GetPreparer(ctx context.Context, snapshotID uuid.UUID) (*http.Request, error) {
246 urlParameters := map[string]interface{}{
247 "Endpoint": client.Endpoint,
248 }
249
250 pathParameters := map[string]interface{}{
251 "snapshotId": autorest.Encode("path", snapshotID),
252 }
253
254 preparer := autorest.CreatePreparer(
255 autorest.AsGet(),
256 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
257 autorest.WithPathParameters("/snapshots/{snapshotId}", pathParameters))
258 return preparer.Prepare((&http.Request{}).WithContext(ctx))
259 }
260
261
262
263 func (client SnapshotClient) GetSender(req *http.Request) (*http.Response, error) {
264 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
265 }
266
267
268
269 func (client SnapshotClient) GetResponder(resp *http.Response) (result Snapshot, err error) {
270 err = autorest.Respond(
271 resp,
272 azure.WithErrorUnlessStatusCode(http.StatusOK),
273 autorest.ByUnmarshallingJSON(&result),
274 autorest.ByClosing())
275 result.Response = autorest.Response{Response: resp}
276 return
277 }
278
279
280
281
282 func (client SnapshotClient) GetOperationStatus(ctx context.Context, operationID uuid.UUID) (result OperationStatus, err error) {
283 if tracing.IsEnabled() {
284 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.GetOperationStatus")
285 defer func() {
286 sc := -1
287 if result.Response.Response != nil {
288 sc = result.Response.Response.StatusCode
289 }
290 tracing.EndSpan(ctx, sc, err)
291 }()
292 }
293 req, err := client.GetOperationStatusPreparer(ctx, operationID)
294 if err != nil {
295 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "GetOperationStatus", nil, "Failure preparing request")
296 return
297 }
298
299 resp, err := client.GetOperationStatusSender(req)
300 if err != nil {
301 result.Response = autorest.Response{Response: resp}
302 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "GetOperationStatus", resp, "Failure sending request")
303 return
304 }
305
306 result, err = client.GetOperationStatusResponder(resp)
307 if err != nil {
308 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "GetOperationStatus", resp, "Failure responding to request")
309 return
310 }
311
312 return
313 }
314
315
316 func (client SnapshotClient) GetOperationStatusPreparer(ctx context.Context, operationID uuid.UUID) (*http.Request, error) {
317 urlParameters := map[string]interface{}{
318 "Endpoint": client.Endpoint,
319 }
320
321 pathParameters := map[string]interface{}{
322 "operationId": autorest.Encode("path", operationID),
323 }
324
325 preparer := autorest.CreatePreparer(
326 autorest.AsGet(),
327 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
328 autorest.WithPathParameters("/operations/{operationId}", pathParameters))
329 return preparer.Prepare((&http.Request{}).WithContext(ctx))
330 }
331
332
333
334 func (client SnapshotClient) GetOperationStatusSender(req *http.Request) (*http.Response, error) {
335 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
336 }
337
338
339
340 func (client SnapshotClient) GetOperationStatusResponder(resp *http.Response) (result OperationStatus, err error) {
341 err = autorest.Respond(
342 resp,
343 azure.WithErrorUnlessStatusCode(http.StatusOK),
344 autorest.ByUnmarshallingJSON(&result),
345 autorest.ByClosing())
346 result.Response = autorest.Response{Response: resp}
347 return
348 }
349
350
351
352
353
354
355
356 func (client SnapshotClient) List(ctx context.Context, typeParameter SnapshotObjectType, applyScope []uuid.UUID) (result ListSnapshot, err error) {
357 if tracing.IsEnabled() {
358 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.List")
359 defer func() {
360 sc := -1
361 if result.Response.Response != nil {
362 sc = result.Response.Response.StatusCode
363 }
364 tracing.EndSpan(ctx, sc, err)
365 }()
366 }
367 req, err := client.ListPreparer(ctx, typeParameter, applyScope)
368 if err != nil {
369 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "List", nil, "Failure preparing request")
370 return
371 }
372
373 resp, err := client.ListSender(req)
374 if err != nil {
375 result.Response = autorest.Response{Response: resp}
376 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "List", resp, "Failure sending request")
377 return
378 }
379
380 result, err = client.ListResponder(resp)
381 if err != nil {
382 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "List", resp, "Failure responding to request")
383 return
384 }
385
386 return
387 }
388
389
390 func (client SnapshotClient) ListPreparer(ctx context.Context, typeParameter SnapshotObjectType, applyScope []uuid.UUID) (*http.Request, error) {
391 urlParameters := map[string]interface{}{
392 "Endpoint": client.Endpoint,
393 }
394
395 queryParameters := map[string]interface{}{}
396 if len(string(typeParameter)) > 0 {
397 queryParameters["type"] = autorest.Encode("query", typeParameter)
398 }
399 if applyScope != nil && len(applyScope) > 0 {
400 queryParameters["applyScope"] = autorest.Encode("query", applyScope, ",")
401 }
402
403 preparer := autorest.CreatePreparer(
404 autorest.AsGet(),
405 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
406 autorest.WithPath("/snapshots"),
407 autorest.WithQueryParameters(queryParameters))
408 return preparer.Prepare((&http.Request{}).WithContext(ctx))
409 }
410
411
412
413 func (client SnapshotClient) ListSender(req *http.Request) (*http.Response, error) {
414 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
415 }
416
417
418
419 func (client SnapshotClient) ListResponder(resp *http.Response) (result ListSnapshot, err error) {
420 err = autorest.Respond(
421 resp,
422 azure.WithErrorUnlessStatusCode(http.StatusOK),
423 autorest.ByUnmarshallingJSON(&result.Value),
424 autorest.ByClosing())
425 result.Response = autorest.Response{Response: resp}
426 return
427 }
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455 func (client SnapshotClient) Take(ctx context.Context, body TakeSnapshotRequest) (result autorest.Response, err error) {
456 if tracing.IsEnabled() {
457 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Take")
458 defer func() {
459 sc := -1
460 if result.Response != nil {
461 sc = result.Response.StatusCode
462 }
463 tracing.EndSpan(ctx, sc, err)
464 }()
465 }
466 if err := validation.Validate([]validation.Validation{
467 {TargetValue: body,
468 Constraints: []validation.Constraint{{Target: "body.ObjectID", Name: validation.Null, Rule: true,
469 Chain: []validation.Constraint{{Target: "body.ObjectID", Name: validation.MaxLength, Rule: 64, Chain: nil},
470 {Target: "body.ObjectID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil},
471 }},
472 {Target: "body.ApplyScope", Name: validation.Null, Rule: true, Chain: nil},
473 {Target: "body.UserData", Name: validation.Null, Rule: false,
474 Chain: []validation.Constraint{{Target: "body.UserData", Name: validation.MaxLength, Rule: 16384, Chain: nil}}}}}}); err != nil {
475 return result, validation.NewError("face.SnapshotClient", "Take", err.Error())
476 }
477
478 req, err := client.TakePreparer(ctx, body)
479 if err != nil {
480 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Take", nil, "Failure preparing request")
481 return
482 }
483
484 resp, err := client.TakeSender(req)
485 if err != nil {
486 result.Response = resp
487 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Take", resp, "Failure sending request")
488 return
489 }
490
491 result, err = client.TakeResponder(resp)
492 if err != nil {
493 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Take", resp, "Failure responding to request")
494 return
495 }
496
497 return
498 }
499
500
501 func (client SnapshotClient) TakePreparer(ctx context.Context, body TakeSnapshotRequest) (*http.Request, error) {
502 urlParameters := map[string]interface{}{
503 "Endpoint": client.Endpoint,
504 }
505
506 preparer := autorest.CreatePreparer(
507 autorest.AsContentType("application/json; charset=utf-8"),
508 autorest.AsPost(),
509 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
510 autorest.WithPath("/snapshots"),
511 autorest.WithJSON(body))
512 return preparer.Prepare((&http.Request{}).WithContext(ctx))
513 }
514
515
516
517 func (client SnapshotClient) TakeSender(req *http.Request) (*http.Response, error) {
518 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
519 }
520
521
522
523 func (client SnapshotClient) TakeResponder(resp *http.Response) (result autorest.Response, err error) {
524 err = autorest.Respond(
525 resp,
526 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
527 autorest.ByClosing())
528 result.Response = resp
529 return
530 }
531
532
533
534
535
536
537 func (client SnapshotClient) Update(ctx context.Context, snapshotID uuid.UUID, body UpdateSnapshotRequest) (result autorest.Response, err error) {
538 if tracing.IsEnabled() {
539 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Update")
540 defer func() {
541 sc := -1
542 if result.Response != nil {
543 sc = result.Response.StatusCode
544 }
545 tracing.EndSpan(ctx, sc, err)
546 }()
547 }
548 req, err := client.UpdatePreparer(ctx, snapshotID, body)
549 if err != nil {
550 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Update", nil, "Failure preparing request")
551 return
552 }
553
554 resp, err := client.UpdateSender(req)
555 if err != nil {
556 result.Response = resp
557 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Update", resp, "Failure sending request")
558 return
559 }
560
561 result, err = client.UpdateResponder(resp)
562 if err != nil {
563 err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Update", resp, "Failure responding to request")
564 return
565 }
566
567 return
568 }
569
570
571 func (client SnapshotClient) UpdatePreparer(ctx context.Context, snapshotID uuid.UUID, body UpdateSnapshotRequest) (*http.Request, error) {
572 urlParameters := map[string]interface{}{
573 "Endpoint": client.Endpoint,
574 }
575
576 pathParameters := map[string]interface{}{
577 "snapshotId": autorest.Encode("path", snapshotID),
578 }
579
580 preparer := autorest.CreatePreparer(
581 autorest.AsContentType("application/json; charset=utf-8"),
582 autorest.AsPatch(),
583 autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
584 autorest.WithPathParameters("/snapshots/{snapshotId}", pathParameters),
585 autorest.WithJSON(body))
586 return preparer.Prepare((&http.Request{}).WithContext(ctx))
587 }
588
589
590
591 func (client SnapshotClient) UpdateSender(req *http.Request) (*http.Response, error) {
592 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
593 }
594
595
596
597 func (client SnapshotClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
598 err = autorest.Respond(
599 resp,
600 azure.WithErrorUnlessStatusCode(http.StatusOK),
601 autorest.ByClosing())
602 result.Response = resp
603 return
604 }
605
View as plain text