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 func (client WorkbooksClient) Get(ctx context.Context, resourceGroupName string, resourceName string) (result Workbook, err error) {
222 if tracing.IsEnabled() {
223 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.Get")
224 defer func() {
225 sc := -1
226 if result.Response.Response != nil {
227 sc = result.Response.Response.StatusCode
228 }
229 tracing.EndSpan(ctx, sc, err)
230 }()
231 }
232 if err := validation.Validate([]validation.Validation{
233 {TargetValue: client.SubscriptionID,
234 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
235 {TargetValue: resourceGroupName,
236 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
237 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
238 return result, validation.NewError("insights.WorkbooksClient", "Get", err.Error())
239 }
240
241 req, err := client.GetPreparer(ctx, resourceGroupName, resourceName)
242 if err != nil {
243 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Get", nil, "Failure preparing request")
244 return
245 }
246
247 resp, err := client.GetSender(req)
248 if err != nil {
249 result.Response = autorest.Response{Response: resp}
250 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Get", resp, "Failure sending request")
251 return
252 }
253
254 result, err = client.GetResponder(resp)
255 if err != nil {
256 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Get", resp, "Failure responding to request")
257 return
258 }
259
260 return
261 }
262
263
264 func (client WorkbooksClient) GetPreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
265 pathParameters := map[string]interface{}{
266 "resourceGroupName": autorest.Encode("path", resourceGroupName),
267 "resourceName": autorest.Encode("path", resourceName),
268 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
269 }
270
271 const APIVersion = "2021-08-01"
272 queryParameters := map[string]interface{}{
273 "api-version": APIVersion,
274 }
275
276 preparer := autorest.CreatePreparer(
277 autorest.AsGet(),
278 autorest.WithBaseURL(client.BaseURI),
279 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/workbooks/{resourceName}", pathParameters),
280 autorest.WithQueryParameters(queryParameters))
281 return preparer.Prepare((&http.Request{}).WithContext(ctx))
282 }
283
284
285
286 func (client WorkbooksClient) GetSender(req *http.Request) (*http.Response, error) {
287 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
288 }
289
290
291
292 func (client WorkbooksClient) GetResponder(resp *http.Response) (result Workbook, err error) {
293 err = autorest.Respond(
294 resp,
295 azure.WithErrorUnlessStatusCode(http.StatusOK),
296 autorest.ByUnmarshallingJSON(&result),
297 autorest.ByClosing())
298 result.Response = autorest.Response{Response: resp}
299 return
300 }
301
302
303
304
305
306
307
308
309
310 func (client WorkbooksClient) ListByResourceGroup(ctx context.Context, resourceGroupName string, category CategoryType, tags []string, sourceID string, canFetchContent *bool) (result WorkbooksListResultPage, err error) {
311 if tracing.IsEnabled() {
312 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.ListByResourceGroup")
313 defer func() {
314 sc := -1
315 if result.wlr.Response.Response != nil {
316 sc = result.wlr.Response.Response.StatusCode
317 }
318 tracing.EndSpan(ctx, sc, err)
319 }()
320 }
321 if err := validation.Validate([]validation.Validation{
322 {TargetValue: client.SubscriptionID,
323 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
324 {TargetValue: resourceGroupName,
325 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
326 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
327 return result, validation.NewError("insights.WorkbooksClient", "ListByResourceGroup", err.Error())
328 }
329
330 result.fn = client.listByResourceGroupNextResults
331 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName, category, tags, sourceID, canFetchContent)
332 if err != nil {
333 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListByResourceGroup", nil, "Failure preparing request")
334 return
335 }
336
337 resp, err := client.ListByResourceGroupSender(req)
338 if err != nil {
339 result.wlr.Response = autorest.Response{Response: resp}
340 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListByResourceGroup", resp, "Failure sending request")
341 return
342 }
343
344 result.wlr, err = client.ListByResourceGroupResponder(resp)
345 if err != nil {
346 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListByResourceGroup", resp, "Failure responding to request")
347 return
348 }
349 if result.wlr.hasNextLink() && result.wlr.IsEmpty() {
350 err = result.NextWithContext(ctx)
351 return
352 }
353
354 return
355 }
356
357
358 func (client WorkbooksClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string, category CategoryType, tags []string, sourceID string, canFetchContent *bool) (*http.Request, error) {
359 pathParameters := map[string]interface{}{
360 "resourceGroupName": autorest.Encode("path", resourceGroupName),
361 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
362 }
363
364 const APIVersion = "2021-08-01"
365 queryParameters := map[string]interface{}{
366 "api-version": APIVersion,
367 "category": autorest.Encode("query", category),
368 }
369 if tags != nil && len(tags) > 0 {
370 queryParameters["tags"] = autorest.Encode("query", tags, ",")
371 }
372 if len(sourceID) > 0 {
373 queryParameters["sourceId"] = autorest.Encode("query", sourceID)
374 }
375 if canFetchContent != nil {
376 queryParameters["canFetchContent"] = autorest.Encode("query", *canFetchContent)
377 }
378
379 preparer := autorest.CreatePreparer(
380 autorest.AsGet(),
381 autorest.WithBaseURL(client.BaseURI),
382 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/workbooks", pathParameters),
383 autorest.WithQueryParameters(queryParameters))
384 return preparer.Prepare((&http.Request{}).WithContext(ctx))
385 }
386
387
388
389 func (client WorkbooksClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
390 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
391 }
392
393
394
395 func (client WorkbooksClient) ListByResourceGroupResponder(resp *http.Response) (result WorkbooksListResult, err error) {
396 err = autorest.Respond(
397 resp,
398 azure.WithErrorUnlessStatusCode(http.StatusOK),
399 autorest.ByUnmarshallingJSON(&result),
400 autorest.ByClosing())
401 result.Response = autorest.Response{Response: resp}
402 return
403 }
404
405
406 func (client WorkbooksClient) listByResourceGroupNextResults(ctx context.Context, lastResults WorkbooksListResult) (result WorkbooksListResult, err error) {
407 req, err := lastResults.workbooksListResultPreparer(ctx)
408 if err != nil {
409 return result, autorest.NewErrorWithError(err, "insights.WorkbooksClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
410 }
411 if req == nil {
412 return
413 }
414 resp, err := client.ListByResourceGroupSender(req)
415 if err != nil {
416 result.Response = autorest.Response{Response: resp}
417 return result, autorest.NewErrorWithError(err, "insights.WorkbooksClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
418 }
419 result, err = client.ListByResourceGroupResponder(resp)
420 if err != nil {
421 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
422 }
423 return
424 }
425
426
427 func (client WorkbooksClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string, category CategoryType, tags []string, sourceID string, canFetchContent *bool) (result WorkbooksListResultIterator, err error) {
428 if tracing.IsEnabled() {
429 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.ListByResourceGroup")
430 defer func() {
431 sc := -1
432 if result.Response().Response.Response != nil {
433 sc = result.page.Response().Response.Response.StatusCode
434 }
435 tracing.EndSpan(ctx, sc, err)
436 }()
437 }
438 result.page, err = client.ListByResourceGroup(ctx, resourceGroupName, category, tags, sourceID, canFetchContent)
439 return
440 }
441
442
443
444
445
446
447
448 func (client WorkbooksClient) ListBySubscription(ctx context.Context, category CategoryType, tags []string, canFetchContent *bool) (result WorkbooksListResultPage, err error) {
449 if tracing.IsEnabled() {
450 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.ListBySubscription")
451 defer func() {
452 sc := -1
453 if result.wlr.Response.Response != nil {
454 sc = result.wlr.Response.Response.StatusCode
455 }
456 tracing.EndSpan(ctx, sc, err)
457 }()
458 }
459 if err := validation.Validate([]validation.Validation{
460 {TargetValue: client.SubscriptionID,
461 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
462 return result, validation.NewError("insights.WorkbooksClient", "ListBySubscription", err.Error())
463 }
464
465 result.fn = client.listBySubscriptionNextResults
466 req, err := client.ListBySubscriptionPreparer(ctx, category, tags, canFetchContent)
467 if err != nil {
468 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListBySubscription", nil, "Failure preparing request")
469 return
470 }
471
472 resp, err := client.ListBySubscriptionSender(req)
473 if err != nil {
474 result.wlr.Response = autorest.Response{Response: resp}
475 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListBySubscription", resp, "Failure sending request")
476 return
477 }
478
479 result.wlr, err = client.ListBySubscriptionResponder(resp)
480 if err != nil {
481 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListBySubscription", resp, "Failure responding to request")
482 return
483 }
484 if result.wlr.hasNextLink() && result.wlr.IsEmpty() {
485 err = result.NextWithContext(ctx)
486 return
487 }
488
489 return
490 }
491
492
493 func (client WorkbooksClient) ListBySubscriptionPreparer(ctx context.Context, category CategoryType, tags []string, canFetchContent *bool) (*http.Request, error) {
494 pathParameters := map[string]interface{}{
495 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
496 }
497
498 const APIVersion = "2021-08-01"
499 queryParameters := map[string]interface{}{
500 "api-version": APIVersion,
501 "category": autorest.Encode("query", category),
502 }
503 if tags != nil && len(tags) > 0 {
504 queryParameters["tags"] = autorest.Encode("query", tags, ",")
505 }
506 if canFetchContent != nil {
507 queryParameters["canFetchContent"] = autorest.Encode("query", *canFetchContent)
508 }
509
510 preparer := autorest.CreatePreparer(
511 autorest.AsGet(),
512 autorest.WithBaseURL(client.BaseURI),
513 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Insights/workbooks", pathParameters),
514 autorest.WithQueryParameters(queryParameters))
515 return preparer.Prepare((&http.Request{}).WithContext(ctx))
516 }
517
518
519
520 func (client WorkbooksClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
521 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
522 }
523
524
525
526 func (client WorkbooksClient) ListBySubscriptionResponder(resp *http.Response) (result WorkbooksListResult, err error) {
527 err = autorest.Respond(
528 resp,
529 azure.WithErrorUnlessStatusCode(http.StatusOK),
530 autorest.ByUnmarshallingJSON(&result),
531 autorest.ByClosing())
532 result.Response = autorest.Response{Response: resp}
533 return
534 }
535
536
537 func (client WorkbooksClient) listBySubscriptionNextResults(ctx context.Context, lastResults WorkbooksListResult) (result WorkbooksListResult, err error) {
538 req, err := lastResults.workbooksListResultPreparer(ctx)
539 if err != nil {
540 return result, autorest.NewErrorWithError(err, "insights.WorkbooksClient", "listBySubscriptionNextResults", nil, "Failure preparing next results request")
541 }
542 if req == nil {
543 return
544 }
545 resp, err := client.ListBySubscriptionSender(req)
546 if err != nil {
547 result.Response = autorest.Response{Response: resp}
548 return result, autorest.NewErrorWithError(err, "insights.WorkbooksClient", "listBySubscriptionNextResults", resp, "Failure sending next results request")
549 }
550 result, err = client.ListBySubscriptionResponder(resp)
551 if err != nil {
552 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "listBySubscriptionNextResults", resp, "Failure responding to next results request")
553 }
554 return
555 }
556
557
558 func (client WorkbooksClient) ListBySubscriptionComplete(ctx context.Context, category CategoryType, tags []string, canFetchContent *bool) (result WorkbooksListResultIterator, err error) {
559 if tracing.IsEnabled() {
560 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.ListBySubscription")
561 defer func() {
562 sc := -1
563 if result.Response().Response.Response != nil {
564 sc = result.page.Response().Response.Response.StatusCode
565 }
566 tracing.EndSpan(ctx, sc, err)
567 }()
568 }
569 result.page, err = client.ListBySubscription(ctx, category, tags, canFetchContent)
570 return
571 }
572
573
574
575
576
577
578 func (client WorkbooksClient) RevisionGet(ctx context.Context, resourceGroupName string, resourceName string, revisionID string) (result Workbook, err error) {
579 if tracing.IsEnabled() {
580 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.RevisionGet")
581 defer func() {
582 sc := -1
583 if result.Response.Response != nil {
584 sc = result.Response.Response.StatusCode
585 }
586 tracing.EndSpan(ctx, sc, err)
587 }()
588 }
589 if err := validation.Validate([]validation.Validation{
590 {TargetValue: client.SubscriptionID,
591 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
592 {TargetValue: resourceGroupName,
593 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
594 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
595 return result, validation.NewError("insights.WorkbooksClient", "RevisionGet", err.Error())
596 }
597
598 req, err := client.RevisionGetPreparer(ctx, resourceGroupName, resourceName, revisionID)
599 if err != nil {
600 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "RevisionGet", nil, "Failure preparing request")
601 return
602 }
603
604 resp, err := client.RevisionGetSender(req)
605 if err != nil {
606 result.Response = autorest.Response{Response: resp}
607 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "RevisionGet", resp, "Failure sending request")
608 return
609 }
610
611 result, err = client.RevisionGetResponder(resp)
612 if err != nil {
613 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "RevisionGet", resp, "Failure responding to request")
614 return
615 }
616
617 return
618 }
619
620
621 func (client WorkbooksClient) RevisionGetPreparer(ctx context.Context, resourceGroupName string, resourceName string, revisionID string) (*http.Request, error) {
622 pathParameters := map[string]interface{}{
623 "resourceGroupName": autorest.Encode("path", resourceGroupName),
624 "resourceName": autorest.Encode("path", resourceName),
625 "revisionId": autorest.Encode("path", revisionID),
626 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
627 }
628
629 const APIVersion = "2021-08-01"
630 queryParameters := map[string]interface{}{
631 "api-version": APIVersion,
632 }
633
634 preparer := autorest.CreatePreparer(
635 autorest.AsGet(),
636 autorest.WithBaseURL(client.BaseURI),
637 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/workbooks/{resourceName}/revisions/{revisionId}", pathParameters),
638 autorest.WithQueryParameters(queryParameters))
639 return preparer.Prepare((&http.Request{}).WithContext(ctx))
640 }
641
642
643
644 func (client WorkbooksClient) RevisionGetSender(req *http.Request) (*http.Response, error) {
645 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
646 }
647
648
649
650 func (client WorkbooksClient) RevisionGetResponder(resp *http.Response) (result Workbook, err error) {
651 err = autorest.Respond(
652 resp,
653 azure.WithErrorUnlessStatusCode(http.StatusOK),
654 autorest.ByUnmarshallingJSON(&result),
655 autorest.ByClosing())
656 result.Response = autorest.Response{Response: resp}
657 return
658 }
659
660
661
662
663
664 func (client WorkbooksClient) RevisionsList(ctx context.Context, resourceGroupName string, resourceName string) (result WorkbooksListResultPage, err error) {
665 if tracing.IsEnabled() {
666 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.RevisionsList")
667 defer func() {
668 sc := -1
669 if result.wlr.Response.Response != nil {
670 sc = result.wlr.Response.Response.StatusCode
671 }
672 tracing.EndSpan(ctx, sc, err)
673 }()
674 }
675 if err := validation.Validate([]validation.Validation{
676 {TargetValue: client.SubscriptionID,
677 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
678 {TargetValue: resourceGroupName,
679 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
680 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
681 return result, validation.NewError("insights.WorkbooksClient", "RevisionsList", err.Error())
682 }
683
684 result.fn = client.revisionsListNextResults
685 req, err := client.RevisionsListPreparer(ctx, resourceGroupName, resourceName)
686 if err != nil {
687 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "RevisionsList", nil, "Failure preparing request")
688 return
689 }
690
691 resp, err := client.RevisionsListSender(req)
692 if err != nil {
693 result.wlr.Response = autorest.Response{Response: resp}
694 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "RevisionsList", resp, "Failure sending request")
695 return
696 }
697
698 result.wlr, err = client.RevisionsListResponder(resp)
699 if err != nil {
700 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "RevisionsList", resp, "Failure responding to request")
701 return
702 }
703 if result.wlr.hasNextLink() && result.wlr.IsEmpty() {
704 err = result.NextWithContext(ctx)
705 return
706 }
707
708 return
709 }
710
711
712 func (client WorkbooksClient) RevisionsListPreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
713 pathParameters := map[string]interface{}{
714 "resourceGroupName": autorest.Encode("path", resourceGroupName),
715 "resourceName": autorest.Encode("path", resourceName),
716 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
717 }
718
719 const APIVersion = "2021-08-01"
720 queryParameters := map[string]interface{}{
721 "api-version": APIVersion,
722 }
723
724 preparer := autorest.CreatePreparer(
725 autorest.AsGet(),
726 autorest.WithBaseURL(client.BaseURI),
727 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/workbooks/{resourceName}/revisions", pathParameters),
728 autorest.WithQueryParameters(queryParameters))
729 return preparer.Prepare((&http.Request{}).WithContext(ctx))
730 }
731
732
733
734 func (client WorkbooksClient) RevisionsListSender(req *http.Request) (*http.Response, error) {
735 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
736 }
737
738
739
740 func (client WorkbooksClient) RevisionsListResponder(resp *http.Response) (result WorkbooksListResult, err error) {
741 err = autorest.Respond(
742 resp,
743 azure.WithErrorUnlessStatusCode(http.StatusOK),
744 autorest.ByUnmarshallingJSON(&result),
745 autorest.ByClosing())
746 result.Response = autorest.Response{Response: resp}
747 return
748 }
749
750
751 func (client WorkbooksClient) revisionsListNextResults(ctx context.Context, lastResults WorkbooksListResult) (result WorkbooksListResult, err error) {
752 req, err := lastResults.workbooksListResultPreparer(ctx)
753 if err != nil {
754 return result, autorest.NewErrorWithError(err, "insights.WorkbooksClient", "revisionsListNextResults", nil, "Failure preparing next results request")
755 }
756 if req == nil {
757 return
758 }
759 resp, err := client.RevisionsListSender(req)
760 if err != nil {
761 result.Response = autorest.Response{Response: resp}
762 return result, autorest.NewErrorWithError(err, "insights.WorkbooksClient", "revisionsListNextResults", resp, "Failure sending next results request")
763 }
764 result, err = client.RevisionsListResponder(resp)
765 if err != nil {
766 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "revisionsListNextResults", resp, "Failure responding to next results request")
767 }
768 return
769 }
770
771
772 func (client WorkbooksClient) RevisionsListComplete(ctx context.Context, resourceGroupName string, resourceName string) (result WorkbooksListResultIterator, err error) {
773 if tracing.IsEnabled() {
774 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.RevisionsList")
775 defer func() {
776 sc := -1
777 if result.Response().Response.Response != nil {
778 sc = result.page.Response().Response.Response.StatusCode
779 }
780 tracing.EndSpan(ctx, sc, err)
781 }()
782 }
783 result.page, err = client.RevisionsList(ctx, resourceGroupName, resourceName)
784 return
785 }
786
787
788
789
790
791
792
793 func (client WorkbooksClient) Update(ctx context.Context, resourceGroupName string, resourceName string, sourceID string, workbookUpdateParameters *WorkbookUpdateParameters) (result Workbook, err error) {
794 if tracing.IsEnabled() {
795 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.Update")
796 defer func() {
797 sc := -1
798 if result.Response.Response != nil {
799 sc = result.Response.Response.StatusCode
800 }
801 tracing.EndSpan(ctx, sc, err)
802 }()
803 }
804 if err := validation.Validate([]validation.Validation{
805 {TargetValue: client.SubscriptionID,
806 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
807 {TargetValue: resourceGroupName,
808 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
809 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
810 return result, validation.NewError("insights.WorkbooksClient", "Update", err.Error())
811 }
812
813 req, err := client.UpdatePreparer(ctx, resourceGroupName, resourceName, sourceID, workbookUpdateParameters)
814 if err != nil {
815 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Update", nil, "Failure preparing request")
816 return
817 }
818
819 resp, err := client.UpdateSender(req)
820 if err != nil {
821 result.Response = autorest.Response{Response: resp}
822 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Update", resp, "Failure sending request")
823 return
824 }
825
826 result, err = client.UpdateResponder(resp)
827 if err != nil {
828 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Update", resp, "Failure responding to request")
829 return
830 }
831
832 return
833 }
834
835
836 func (client WorkbooksClient) UpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, sourceID string, workbookUpdateParameters *WorkbookUpdateParameters) (*http.Request, error) {
837 pathParameters := map[string]interface{}{
838 "resourceGroupName": autorest.Encode("path", resourceGroupName),
839 "resourceName": autorest.Encode("path", resourceName),
840 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
841 }
842
843 const APIVersion = "2021-08-01"
844 queryParameters := map[string]interface{}{
845 "api-version": APIVersion,
846 }
847 if len(sourceID) > 0 {
848 queryParameters["sourceId"] = autorest.Encode("query", sourceID)
849 }
850
851 preparer := autorest.CreatePreparer(
852 autorest.AsContentType("application/json; charset=utf-8"),
853 autorest.AsPatch(),
854 autorest.WithBaseURL(client.BaseURI),
855 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/workbooks/{resourceName}", pathParameters),
856 autorest.WithQueryParameters(queryParameters))
857 if workbookUpdateParameters != nil {
858 preparer = autorest.DecoratePreparer(preparer,
859 autorest.WithJSON(workbookUpdateParameters))
860 }
861 return preparer.Prepare((&http.Request{}).WithContext(ctx))
862 }
863
864
865
866 func (client WorkbooksClient) UpdateSender(req *http.Request) (*http.Response, error) {
867 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
868 }
869
870
871
872 func (client WorkbooksClient) UpdateResponder(resp *http.Response) (result Workbook, err error) {
873 err = autorest.Respond(
874 resp,
875 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
876 autorest.ByUnmarshallingJSON(&result),
877 autorest.ByClosing())
878 result.Response = autorest.Response{Response: resp}
879 return
880 }
881
View as plain text