1 package insights
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 "net/http"
16 )
17
18
19 type WorkbooksClient struct {
20 BaseClient
21 }
22
23
24 func NewWorkbooksClient(subscriptionID string) WorkbooksClient {
25 return NewWorkbooksClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewWorkbooksClientWithBaseURI(baseURI string, subscriptionID string) WorkbooksClient {
31 return WorkbooksClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40 func (client WorkbooksClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, resourceName string, workbookProperties Workbook, sourceID string) (result Workbook, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.CreateOrUpdate")
43 defer func() {
44 sc := -1
45 if result.Response.Response != nil {
46 sc = result.Response.Response.StatusCode
47 }
48 tracing.EndSpan(ctx, sc, err)
49 }()
50 }
51 if err := validation.Validate([]validation.Validation{
52 {TargetValue: client.SubscriptionID,
53 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
54 {TargetValue: resourceGroupName,
55 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
56 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
57 {TargetValue: workbookProperties,
58 Constraints: []validation.Constraint{{Target: "workbookProperties.WorkbookProperties", Name: validation.Null, Rule: false,
59 Chain: []validation.Constraint{{Target: "workbookProperties.WorkbookProperties.DisplayName", Name: validation.Null, Rule: true, Chain: nil},
60 {Target: "workbookProperties.WorkbookProperties.SerializedData", Name: validation.Null, Rule: true, Chain: nil},
61 {Target: "workbookProperties.WorkbookProperties.Category", Name: validation.Null, Rule: true, Chain: nil},
62 }}}}}); err != nil {
63 return result, validation.NewError("insights.WorkbooksClient", "CreateOrUpdate", err.Error())
64 }
65
66 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, resourceName, workbookProperties, sourceID)
67 if err != nil {
68 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "CreateOrUpdate", nil, "Failure preparing request")
69 return
70 }
71
72 resp, err := client.CreateOrUpdateSender(req)
73 if err != nil {
74 result.Response = autorest.Response{Response: resp}
75 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "CreateOrUpdate", resp, "Failure sending request")
76 return
77 }
78
79 result, err = client.CreateOrUpdateResponder(resp)
80 if err != nil {
81 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "CreateOrUpdate", resp, "Failure responding to request")
82 return
83 }
84
85 return
86 }
87
88
89 func (client WorkbooksClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, workbookProperties Workbook, sourceID string) (*http.Request, error) {
90 pathParameters := map[string]interface{}{
91 "resourceGroupName": autorest.Encode("path", resourceGroupName),
92 "resourceName": autorest.Encode("path", resourceName),
93 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
94 }
95
96 const APIVersion = "2021-08-01"
97 queryParameters := map[string]interface{}{
98 "api-version": APIVersion,
99 }
100 if len(sourceID) > 0 {
101 queryParameters["sourceId"] = autorest.Encode("query", sourceID)
102 }
103
104 workbookProperties.SystemData = nil
105 preparer := autorest.CreatePreparer(
106 autorest.AsContentType("application/json; charset=utf-8"),
107 autorest.AsPut(),
108 autorest.WithBaseURL(client.BaseURI),
109 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/workbooks/{resourceName}", pathParameters),
110 autorest.WithJSON(workbookProperties),
111 autorest.WithQueryParameters(queryParameters))
112 return preparer.Prepare((&http.Request{}).WithContext(ctx))
113 }
114
115
116
117 func (client WorkbooksClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
118 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
119 }
120
121
122
123 func (client WorkbooksClient) CreateOrUpdateResponder(resp *http.Response) (result Workbook, err error) {
124 err = autorest.Respond(
125 resp,
126 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
127 autorest.ByUnmarshallingJSON(&result),
128 autorest.ByClosing())
129 result.Response = autorest.Response{Response: resp}
130 return
131 }
132
133
134
135
136
137 func (client WorkbooksClient) Delete(ctx context.Context, resourceGroupName string, resourceName string) (result autorest.Response, err error) {
138 if tracing.IsEnabled() {
139 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.Delete")
140 defer func() {
141 sc := -1
142 if result.Response != nil {
143 sc = result.Response.StatusCode
144 }
145 tracing.EndSpan(ctx, sc, err)
146 }()
147 }
148 if err := validation.Validate([]validation.Validation{
149 {TargetValue: client.SubscriptionID,
150 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
151 {TargetValue: resourceGroupName,
152 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
153 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
154 return result, validation.NewError("insights.WorkbooksClient", "Delete", err.Error())
155 }
156
157 req, err := client.DeletePreparer(ctx, resourceGroupName, resourceName)
158 if err != nil {
159 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Delete", nil, "Failure preparing request")
160 return
161 }
162
163 resp, err := client.DeleteSender(req)
164 if err != nil {
165 result.Response = resp
166 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Delete", resp, "Failure sending request")
167 return
168 }
169
170 result, err = client.DeleteResponder(resp)
171 if err != nil {
172 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Delete", resp, "Failure responding to request")
173 return
174 }
175
176 return
177 }
178
179
180 func (client WorkbooksClient) DeletePreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
181 pathParameters := map[string]interface{}{
182 "resourceGroupName": autorest.Encode("path", resourceGroupName),
183 "resourceName": autorest.Encode("path", resourceName),
184 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
185 }
186
187 const APIVersion = "2021-08-01"
188 queryParameters := map[string]interface{}{
189 "api-version": APIVersion,
190 }
191
192 preparer := autorest.CreatePreparer(
193 autorest.AsDelete(),
194 autorest.WithBaseURL(client.BaseURI),
195 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/workbooks/{resourceName}", pathParameters),
196 autorest.WithQueryParameters(queryParameters))
197 return preparer.Prepare((&http.Request{}).WithContext(ctx))
198 }
199
200
201
202 func (client WorkbooksClient) DeleteSender(req *http.Request) (*http.Response, error) {
203 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
204 }
205
206
207
208 func (client WorkbooksClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
209 err = autorest.Respond(
210 resp,
211 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
212 autorest.ByClosing())
213 result.Response = resp
214 return
215 }
216
217
218
219
220
221
222
223 func (client WorkbooksClient) Get(ctx context.Context, resourceGroupName string, resourceName string, canFetchContent *bool) (result Workbook, err error) {
224 if tracing.IsEnabled() {
225 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.Get")
226 defer func() {
227 sc := -1
228 if result.Response.Response != nil {
229 sc = result.Response.Response.StatusCode
230 }
231 tracing.EndSpan(ctx, sc, err)
232 }()
233 }
234 if err := validation.Validate([]validation.Validation{
235 {TargetValue: client.SubscriptionID,
236 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
237 {TargetValue: resourceGroupName,
238 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
239 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
240 return result, validation.NewError("insights.WorkbooksClient", "Get", err.Error())
241 }
242
243 req, err := client.GetPreparer(ctx, resourceGroupName, resourceName, canFetchContent)
244 if err != nil {
245 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Get", nil, "Failure preparing request")
246 return
247 }
248
249 resp, err := client.GetSender(req)
250 if err != nil {
251 result.Response = autorest.Response{Response: resp}
252 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Get", resp, "Failure sending request")
253 return
254 }
255
256 result, err = client.GetResponder(resp)
257 if err != nil {
258 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Get", resp, "Failure responding to request")
259 return
260 }
261
262 return
263 }
264
265
266 func (client WorkbooksClient) GetPreparer(ctx context.Context, resourceGroupName string, resourceName string, canFetchContent *bool) (*http.Request, error) {
267 pathParameters := map[string]interface{}{
268 "resourceGroupName": autorest.Encode("path", resourceGroupName),
269 "resourceName": autorest.Encode("path", resourceName),
270 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
271 }
272
273 const APIVersion = "2021-08-01"
274 queryParameters := map[string]interface{}{
275 "api-version": APIVersion,
276 }
277 if canFetchContent != nil {
278 queryParameters["canFetchContent"] = autorest.Encode("query", *canFetchContent)
279 }
280
281 preparer := autorest.CreatePreparer(
282 autorest.AsGet(),
283 autorest.WithBaseURL(client.BaseURI),
284 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/workbooks/{resourceName}", pathParameters),
285 autorest.WithQueryParameters(queryParameters))
286 return preparer.Prepare((&http.Request{}).WithContext(ctx))
287 }
288
289
290
291 func (client WorkbooksClient) GetSender(req *http.Request) (*http.Response, error) {
292 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
293 }
294
295
296
297 func (client WorkbooksClient) GetResponder(resp *http.Response) (result Workbook, err error) {
298 err = autorest.Respond(
299 resp,
300 azure.WithErrorUnlessStatusCode(http.StatusOK),
301 autorest.ByUnmarshallingJSON(&result),
302 autorest.ByClosing())
303 result.Response = autorest.Response{Response: resp}
304 return
305 }
306
307
308
309
310
311
312
313
314
315 func (client WorkbooksClient) ListByResourceGroup(ctx context.Context, resourceGroupName string, category CategoryType, tags []string, sourceID string, canFetchContent *bool) (result WorkbooksListResultPage, err error) {
316 if tracing.IsEnabled() {
317 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.ListByResourceGroup")
318 defer func() {
319 sc := -1
320 if result.wlr.Response.Response != nil {
321 sc = result.wlr.Response.Response.StatusCode
322 }
323 tracing.EndSpan(ctx, sc, err)
324 }()
325 }
326 if err := validation.Validate([]validation.Validation{
327 {TargetValue: client.SubscriptionID,
328 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
329 {TargetValue: resourceGroupName,
330 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
331 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
332 return result, validation.NewError("insights.WorkbooksClient", "ListByResourceGroup", err.Error())
333 }
334
335 result.fn = client.listByResourceGroupNextResults
336 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName, category, tags, sourceID, canFetchContent)
337 if err != nil {
338 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListByResourceGroup", nil, "Failure preparing request")
339 return
340 }
341
342 resp, err := client.ListByResourceGroupSender(req)
343 if err != nil {
344 result.wlr.Response = autorest.Response{Response: resp}
345 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListByResourceGroup", resp, "Failure sending request")
346 return
347 }
348
349 result.wlr, err = client.ListByResourceGroupResponder(resp)
350 if err != nil {
351 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListByResourceGroup", resp, "Failure responding to request")
352 return
353 }
354 if result.wlr.hasNextLink() && result.wlr.IsEmpty() {
355 err = result.NextWithContext(ctx)
356 return
357 }
358
359 return
360 }
361
362
363 func (client WorkbooksClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string, category CategoryType, tags []string, sourceID string, canFetchContent *bool) (*http.Request, error) {
364 pathParameters := map[string]interface{}{
365 "resourceGroupName": autorest.Encode("path", resourceGroupName),
366 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
367 }
368
369 const APIVersion = "2021-08-01"
370 queryParameters := map[string]interface{}{
371 "api-version": APIVersion,
372 "category": autorest.Encode("query", category),
373 }
374 if tags != nil && len(tags) > 0 {
375 queryParameters["tags"] = autorest.Encode("query", tags, ",")
376 }
377 if len(sourceID) > 0 {
378 queryParameters["sourceId"] = autorest.Encode("query", sourceID)
379 }
380 if canFetchContent != nil {
381 queryParameters["canFetchContent"] = autorest.Encode("query", *canFetchContent)
382 }
383
384 preparer := autorest.CreatePreparer(
385 autorest.AsGet(),
386 autorest.WithBaseURL(client.BaseURI),
387 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/workbooks", pathParameters),
388 autorest.WithQueryParameters(queryParameters))
389 return preparer.Prepare((&http.Request{}).WithContext(ctx))
390 }
391
392
393
394 func (client WorkbooksClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
395 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
396 }
397
398
399
400 func (client WorkbooksClient) ListByResourceGroupResponder(resp *http.Response) (result WorkbooksListResult, err error) {
401 err = autorest.Respond(
402 resp,
403 azure.WithErrorUnlessStatusCode(http.StatusOK),
404 autorest.ByUnmarshallingJSON(&result),
405 autorest.ByClosing())
406 result.Response = autorest.Response{Response: resp}
407 return
408 }
409
410
411 func (client WorkbooksClient) listByResourceGroupNextResults(ctx context.Context, lastResults WorkbooksListResult) (result WorkbooksListResult, err error) {
412 req, err := lastResults.workbooksListResultPreparer(ctx)
413 if err != nil {
414 return result, autorest.NewErrorWithError(err, "insights.WorkbooksClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
415 }
416 if req == nil {
417 return
418 }
419 resp, err := client.ListByResourceGroupSender(req)
420 if err != nil {
421 result.Response = autorest.Response{Response: resp}
422 return result, autorest.NewErrorWithError(err, "insights.WorkbooksClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
423 }
424 result, err = client.ListByResourceGroupResponder(resp)
425 if err != nil {
426 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
427 }
428 return
429 }
430
431
432 func (client WorkbooksClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string, category CategoryType, tags []string, sourceID string, canFetchContent *bool) (result WorkbooksListResultIterator, err error) {
433 if tracing.IsEnabled() {
434 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.ListByResourceGroup")
435 defer func() {
436 sc := -1
437 if result.Response().Response.Response != nil {
438 sc = result.page.Response().Response.Response.StatusCode
439 }
440 tracing.EndSpan(ctx, sc, err)
441 }()
442 }
443 result.page, err = client.ListByResourceGroup(ctx, resourceGroupName, category, tags, sourceID, canFetchContent)
444 return
445 }
446
447
448
449
450
451
452
453 func (client WorkbooksClient) ListBySubscription(ctx context.Context, category CategoryType, tags []string, canFetchContent *bool) (result WorkbooksListResultPage, err error) {
454 if tracing.IsEnabled() {
455 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.ListBySubscription")
456 defer func() {
457 sc := -1
458 if result.wlr.Response.Response != nil {
459 sc = result.wlr.Response.Response.StatusCode
460 }
461 tracing.EndSpan(ctx, sc, err)
462 }()
463 }
464 if err := validation.Validate([]validation.Validation{
465 {TargetValue: client.SubscriptionID,
466 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
467 return result, validation.NewError("insights.WorkbooksClient", "ListBySubscription", err.Error())
468 }
469
470 result.fn = client.listBySubscriptionNextResults
471 req, err := client.ListBySubscriptionPreparer(ctx, category, tags, canFetchContent)
472 if err != nil {
473 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListBySubscription", nil, "Failure preparing request")
474 return
475 }
476
477 resp, err := client.ListBySubscriptionSender(req)
478 if err != nil {
479 result.wlr.Response = autorest.Response{Response: resp}
480 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListBySubscription", resp, "Failure sending request")
481 return
482 }
483
484 result.wlr, err = client.ListBySubscriptionResponder(resp)
485 if err != nil {
486 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListBySubscription", resp, "Failure responding to request")
487 return
488 }
489 if result.wlr.hasNextLink() && result.wlr.IsEmpty() {
490 err = result.NextWithContext(ctx)
491 return
492 }
493
494 return
495 }
496
497
498 func (client WorkbooksClient) ListBySubscriptionPreparer(ctx context.Context, category CategoryType, tags []string, canFetchContent *bool) (*http.Request, error) {
499 pathParameters := map[string]interface{}{
500 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
501 }
502
503 const APIVersion = "2021-08-01"
504 queryParameters := map[string]interface{}{
505 "api-version": APIVersion,
506 "category": autorest.Encode("query", category),
507 }
508 if tags != nil && len(tags) > 0 {
509 queryParameters["tags"] = autorest.Encode("query", tags, ",")
510 }
511 if canFetchContent != nil {
512 queryParameters["canFetchContent"] = autorest.Encode("query", *canFetchContent)
513 }
514
515 preparer := autorest.CreatePreparer(
516 autorest.AsGet(),
517 autorest.WithBaseURL(client.BaseURI),
518 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Insights/workbooks", pathParameters),
519 autorest.WithQueryParameters(queryParameters))
520 return preparer.Prepare((&http.Request{}).WithContext(ctx))
521 }
522
523
524
525 func (client WorkbooksClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
526 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
527 }
528
529
530
531 func (client WorkbooksClient) ListBySubscriptionResponder(resp *http.Response) (result WorkbooksListResult, err error) {
532 err = autorest.Respond(
533 resp,
534 azure.WithErrorUnlessStatusCode(http.StatusOK),
535 autorest.ByUnmarshallingJSON(&result),
536 autorest.ByClosing())
537 result.Response = autorest.Response{Response: resp}
538 return
539 }
540
541
542 func (client WorkbooksClient) listBySubscriptionNextResults(ctx context.Context, lastResults WorkbooksListResult) (result WorkbooksListResult, err error) {
543 req, err := lastResults.workbooksListResultPreparer(ctx)
544 if err != nil {
545 return result, autorest.NewErrorWithError(err, "insights.WorkbooksClient", "listBySubscriptionNextResults", nil, "Failure preparing next results request")
546 }
547 if req == nil {
548 return
549 }
550 resp, err := client.ListBySubscriptionSender(req)
551 if err != nil {
552 result.Response = autorest.Response{Response: resp}
553 return result, autorest.NewErrorWithError(err, "insights.WorkbooksClient", "listBySubscriptionNextResults", resp, "Failure sending next results request")
554 }
555 result, err = client.ListBySubscriptionResponder(resp)
556 if err != nil {
557 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "listBySubscriptionNextResults", resp, "Failure responding to next results request")
558 }
559 return
560 }
561
562
563 func (client WorkbooksClient) ListBySubscriptionComplete(ctx context.Context, category CategoryType, tags []string, canFetchContent *bool) (result WorkbooksListResultIterator, err error) {
564 if tracing.IsEnabled() {
565 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.ListBySubscription")
566 defer func() {
567 sc := -1
568 if result.Response().Response.Response != nil {
569 sc = result.page.Response().Response.Response.StatusCode
570 }
571 tracing.EndSpan(ctx, sc, err)
572 }()
573 }
574 result.page, err = client.ListBySubscription(ctx, category, tags, canFetchContent)
575 return
576 }
577
578
579
580
581
582
583 func (client WorkbooksClient) RevisionGet(ctx context.Context, resourceGroupName string, resourceName string, revisionID string) (result Workbook, err error) {
584 if tracing.IsEnabled() {
585 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.RevisionGet")
586 defer func() {
587 sc := -1
588 if result.Response.Response != nil {
589 sc = result.Response.Response.StatusCode
590 }
591 tracing.EndSpan(ctx, sc, err)
592 }()
593 }
594 if err := validation.Validate([]validation.Validation{
595 {TargetValue: client.SubscriptionID,
596 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
597 {TargetValue: resourceGroupName,
598 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
599 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
600 return result, validation.NewError("insights.WorkbooksClient", "RevisionGet", err.Error())
601 }
602
603 req, err := client.RevisionGetPreparer(ctx, resourceGroupName, resourceName, revisionID)
604 if err != nil {
605 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "RevisionGet", nil, "Failure preparing request")
606 return
607 }
608
609 resp, err := client.RevisionGetSender(req)
610 if err != nil {
611 result.Response = autorest.Response{Response: resp}
612 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "RevisionGet", resp, "Failure sending request")
613 return
614 }
615
616 result, err = client.RevisionGetResponder(resp)
617 if err != nil {
618 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "RevisionGet", resp, "Failure responding to request")
619 return
620 }
621
622 return
623 }
624
625
626 func (client WorkbooksClient) RevisionGetPreparer(ctx context.Context, resourceGroupName string, resourceName string, revisionID string) (*http.Request, error) {
627 pathParameters := map[string]interface{}{
628 "resourceGroupName": autorest.Encode("path", resourceGroupName),
629 "resourceName": autorest.Encode("path", resourceName),
630 "revisionId": autorest.Encode("path", revisionID),
631 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
632 }
633
634 const APIVersion = "2021-08-01"
635 queryParameters := map[string]interface{}{
636 "api-version": APIVersion,
637 }
638
639 preparer := autorest.CreatePreparer(
640 autorest.AsGet(),
641 autorest.WithBaseURL(client.BaseURI),
642 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/workbooks/{resourceName}/revisions/{revisionId}", pathParameters),
643 autorest.WithQueryParameters(queryParameters))
644 return preparer.Prepare((&http.Request{}).WithContext(ctx))
645 }
646
647
648
649 func (client WorkbooksClient) RevisionGetSender(req *http.Request) (*http.Response, error) {
650 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
651 }
652
653
654
655 func (client WorkbooksClient) RevisionGetResponder(resp *http.Response) (result Workbook, err error) {
656 err = autorest.Respond(
657 resp,
658 azure.WithErrorUnlessStatusCode(http.StatusOK),
659 autorest.ByUnmarshallingJSON(&result),
660 autorest.ByClosing())
661 result.Response = autorest.Response{Response: resp}
662 return
663 }
664
665
666
667
668
669 func (client WorkbooksClient) RevisionsList(ctx context.Context, resourceGroupName string, resourceName string) (result WorkbooksListResultPage, err error) {
670 if tracing.IsEnabled() {
671 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.RevisionsList")
672 defer func() {
673 sc := -1
674 if result.wlr.Response.Response != nil {
675 sc = result.wlr.Response.Response.StatusCode
676 }
677 tracing.EndSpan(ctx, sc, err)
678 }()
679 }
680 if err := validation.Validate([]validation.Validation{
681 {TargetValue: client.SubscriptionID,
682 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
683 {TargetValue: resourceGroupName,
684 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
685 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
686 return result, validation.NewError("insights.WorkbooksClient", "RevisionsList", err.Error())
687 }
688
689 result.fn = client.revisionsListNextResults
690 req, err := client.RevisionsListPreparer(ctx, resourceGroupName, resourceName)
691 if err != nil {
692 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "RevisionsList", nil, "Failure preparing request")
693 return
694 }
695
696 resp, err := client.RevisionsListSender(req)
697 if err != nil {
698 result.wlr.Response = autorest.Response{Response: resp}
699 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "RevisionsList", resp, "Failure sending request")
700 return
701 }
702
703 result.wlr, err = client.RevisionsListResponder(resp)
704 if err != nil {
705 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "RevisionsList", resp, "Failure responding to request")
706 return
707 }
708 if result.wlr.hasNextLink() && result.wlr.IsEmpty() {
709 err = result.NextWithContext(ctx)
710 return
711 }
712
713 return
714 }
715
716
717 func (client WorkbooksClient) RevisionsListPreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
718 pathParameters := map[string]interface{}{
719 "resourceGroupName": autorest.Encode("path", resourceGroupName),
720 "resourceName": autorest.Encode("path", resourceName),
721 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
722 }
723
724 const APIVersion = "2021-08-01"
725 queryParameters := map[string]interface{}{
726 "api-version": APIVersion,
727 }
728
729 preparer := autorest.CreatePreparer(
730 autorest.AsGet(),
731 autorest.WithBaseURL(client.BaseURI),
732 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/workbooks/{resourceName}/revisions", pathParameters),
733 autorest.WithQueryParameters(queryParameters))
734 return preparer.Prepare((&http.Request{}).WithContext(ctx))
735 }
736
737
738
739 func (client WorkbooksClient) RevisionsListSender(req *http.Request) (*http.Response, error) {
740 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
741 }
742
743
744
745 func (client WorkbooksClient) RevisionsListResponder(resp *http.Response) (result WorkbooksListResult, err error) {
746 err = autorest.Respond(
747 resp,
748 azure.WithErrorUnlessStatusCode(http.StatusOK),
749 autorest.ByUnmarshallingJSON(&result),
750 autorest.ByClosing())
751 result.Response = autorest.Response{Response: resp}
752 return
753 }
754
755
756 func (client WorkbooksClient) revisionsListNextResults(ctx context.Context, lastResults WorkbooksListResult) (result WorkbooksListResult, err error) {
757 req, err := lastResults.workbooksListResultPreparer(ctx)
758 if err != nil {
759 return result, autorest.NewErrorWithError(err, "insights.WorkbooksClient", "revisionsListNextResults", nil, "Failure preparing next results request")
760 }
761 if req == nil {
762 return
763 }
764 resp, err := client.RevisionsListSender(req)
765 if err != nil {
766 result.Response = autorest.Response{Response: resp}
767 return result, autorest.NewErrorWithError(err, "insights.WorkbooksClient", "revisionsListNextResults", resp, "Failure sending next results request")
768 }
769 result, err = client.RevisionsListResponder(resp)
770 if err != nil {
771 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "revisionsListNextResults", resp, "Failure responding to next results request")
772 }
773 return
774 }
775
776
777 func (client WorkbooksClient) RevisionsListComplete(ctx context.Context, resourceGroupName string, resourceName string) (result WorkbooksListResultIterator, err error) {
778 if tracing.IsEnabled() {
779 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.RevisionsList")
780 defer func() {
781 sc := -1
782 if result.Response().Response.Response != nil {
783 sc = result.page.Response().Response.Response.StatusCode
784 }
785 tracing.EndSpan(ctx, sc, err)
786 }()
787 }
788 result.page, err = client.RevisionsList(ctx, resourceGroupName, resourceName)
789 return
790 }
791
792
793
794
795
796
797
798 func (client WorkbooksClient) Update(ctx context.Context, resourceGroupName string, resourceName string, sourceID string, workbookUpdateParameters *WorkbookUpdateParameters) (result Workbook, err error) {
799 if tracing.IsEnabled() {
800 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.Update")
801 defer func() {
802 sc := -1
803 if result.Response.Response != nil {
804 sc = result.Response.Response.StatusCode
805 }
806 tracing.EndSpan(ctx, sc, err)
807 }()
808 }
809 if err := validation.Validate([]validation.Validation{
810 {TargetValue: client.SubscriptionID,
811 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
812 {TargetValue: resourceGroupName,
813 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
814 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
815 return result, validation.NewError("insights.WorkbooksClient", "Update", err.Error())
816 }
817
818 req, err := client.UpdatePreparer(ctx, resourceGroupName, resourceName, sourceID, workbookUpdateParameters)
819 if err != nil {
820 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Update", nil, "Failure preparing request")
821 return
822 }
823
824 resp, err := client.UpdateSender(req)
825 if err != nil {
826 result.Response = autorest.Response{Response: resp}
827 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Update", resp, "Failure sending request")
828 return
829 }
830
831 result, err = client.UpdateResponder(resp)
832 if err != nil {
833 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Update", resp, "Failure responding to request")
834 return
835 }
836
837 return
838 }
839
840
841 func (client WorkbooksClient) UpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, sourceID string, workbookUpdateParameters *WorkbookUpdateParameters) (*http.Request, error) {
842 pathParameters := map[string]interface{}{
843 "resourceGroupName": autorest.Encode("path", resourceGroupName),
844 "resourceName": autorest.Encode("path", resourceName),
845 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
846 }
847
848 const APIVersion = "2021-08-01"
849 queryParameters := map[string]interface{}{
850 "api-version": APIVersion,
851 }
852 if len(sourceID) > 0 {
853 queryParameters["sourceId"] = autorest.Encode("query", sourceID)
854 }
855
856 preparer := autorest.CreatePreparer(
857 autorest.AsContentType("application/json; charset=utf-8"),
858 autorest.AsPatch(),
859 autorest.WithBaseURL(client.BaseURI),
860 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/workbooks/{resourceName}", pathParameters),
861 autorest.WithQueryParameters(queryParameters))
862 if workbookUpdateParameters != nil {
863 preparer = autorest.DecoratePreparer(preparer,
864 autorest.WithJSON(workbookUpdateParameters))
865 }
866 return preparer.Prepare((&http.Request{}).WithContext(ctx))
867 }
868
869
870
871 func (client WorkbooksClient) UpdateSender(req *http.Request) (*http.Response, error) {
872 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
873 }
874
875
876
877 func (client WorkbooksClient) UpdateResponder(resp *http.Response) (result Workbook, err error) {
878 err = autorest.Respond(
879 resp,
880 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
881 autorest.ByUnmarshallingJSON(&result),
882 autorest.ByClosing())
883 result.Response = autorest.Response{Response: resp}
884 return
885 }
886
View as plain text