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 func (client WorkbooksClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, resourceName string, workbookProperties Workbook) (result Workbook, err error) {
40 if tracing.IsEnabled() {
41 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.CreateOrUpdate")
42 defer func() {
43 sc := -1
44 if result.Response.Response != nil {
45 sc = result.Response.Response.StatusCode
46 }
47 tracing.EndSpan(ctx, sc, err)
48 }()
49 }
50 if err := validation.Validate([]validation.Validation{
51 {TargetValue: client.SubscriptionID,
52 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
53 {TargetValue: resourceGroupName,
54 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
55 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
56 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
57 {TargetValue: workbookProperties,
58 Constraints: []validation.Constraint{{Target: "workbookProperties.WorkbookProperties", Name: validation.Null, Rule: false,
59 Chain: []validation.Constraint{{Target: "workbookProperties.WorkbookProperties.Name", Name: validation.Null, Rule: true, Chain: nil},
60 {Target: "workbookProperties.WorkbookProperties.SerializedData", Name: validation.Null, Rule: true, Chain: nil},
61 {Target: "workbookProperties.WorkbookProperties.WorkbookID", Name: validation.Null, Rule: true, Chain: nil},
62 {Target: "workbookProperties.WorkbookProperties.Category", Name: validation.Null, Rule: true, Chain: nil},
63 {Target: "workbookProperties.WorkbookProperties.UserID", Name: validation.Null, Rule: true, Chain: nil},
64 }}}}}); err != nil {
65 return result, validation.NewError("insights.WorkbooksClient", "CreateOrUpdate", err.Error())
66 }
67
68 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, resourceName, workbookProperties)
69 if err != nil {
70 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "CreateOrUpdate", nil, "Failure preparing request")
71 return
72 }
73
74 resp, err := client.CreateOrUpdateSender(req)
75 if err != nil {
76 result.Response = autorest.Response{Response: resp}
77 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "CreateOrUpdate", resp, "Failure sending request")
78 return
79 }
80
81 result, err = client.CreateOrUpdateResponder(resp)
82 if err != nil {
83 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "CreateOrUpdate", resp, "Failure responding to request")
84 return
85 }
86
87 return
88 }
89
90
91 func (client WorkbooksClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, workbookProperties Workbook) (*http.Request, error) {
92 pathParameters := map[string]interface{}{
93 "resourceGroupName": autorest.Encode("path", resourceGroupName),
94 "resourceName": autorest.Encode("path", resourceName),
95 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
96 }
97
98 const APIVersion = "2015-05-01"
99 queryParameters := map[string]interface{}{
100 "api-version": APIVersion,
101 }
102
103 preparer := autorest.CreatePreparer(
104 autorest.AsContentType("application/json; charset=utf-8"),
105 autorest.AsPut(),
106 autorest.WithBaseURL(client.BaseURI),
107 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/workbooks/{resourceName}", pathParameters),
108 autorest.WithJSON(workbookProperties),
109 autorest.WithQueryParameters(queryParameters))
110 return preparer.Prepare((&http.Request{}).WithContext(ctx))
111 }
112
113
114
115 func (client WorkbooksClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
116 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
117 }
118
119
120
121 func (client WorkbooksClient) CreateOrUpdateResponder(resp *http.Response) (result Workbook, err error) {
122 err = autorest.Respond(
123 resp,
124 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
125 autorest.ByUnmarshallingJSON(&result),
126 autorest.ByClosing())
127 result.Response = autorest.Response{Response: resp}
128 return
129 }
130
131
132
133
134
135 func (client WorkbooksClient) Delete(ctx context.Context, resourceGroupName string, resourceName string) (result autorest.Response, err error) {
136 if tracing.IsEnabled() {
137 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.Delete")
138 defer func() {
139 sc := -1
140 if result.Response != nil {
141 sc = result.Response.StatusCode
142 }
143 tracing.EndSpan(ctx, sc, err)
144 }()
145 }
146 if err := validation.Validate([]validation.Validation{
147 {TargetValue: client.SubscriptionID,
148 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
149 {TargetValue: resourceGroupName,
150 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
151 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
152 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
153 return result, validation.NewError("insights.WorkbooksClient", "Delete", err.Error())
154 }
155
156 req, err := client.DeletePreparer(ctx, resourceGroupName, resourceName)
157 if err != nil {
158 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Delete", nil, "Failure preparing request")
159 return
160 }
161
162 resp, err := client.DeleteSender(req)
163 if err != nil {
164 result.Response = resp
165 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Delete", resp, "Failure sending request")
166 return
167 }
168
169 result, err = client.DeleteResponder(resp)
170 if err != nil {
171 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Delete", resp, "Failure responding to request")
172 return
173 }
174
175 return
176 }
177
178
179 func (client WorkbooksClient) DeletePreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
180 pathParameters := map[string]interface{}{
181 "resourceGroupName": autorest.Encode("path", resourceGroupName),
182 "resourceName": autorest.Encode("path", resourceName),
183 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
184 }
185
186 const APIVersion = "2015-05-01"
187 queryParameters := map[string]interface{}{
188 "api-version": APIVersion,
189 }
190
191 preparer := autorest.CreatePreparer(
192 autorest.AsDelete(),
193 autorest.WithBaseURL(client.BaseURI),
194 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/workbooks/{resourceName}", pathParameters),
195 autorest.WithQueryParameters(queryParameters))
196 return preparer.Prepare((&http.Request{}).WithContext(ctx))
197 }
198
199
200
201 func (client WorkbooksClient) DeleteSender(req *http.Request) (*http.Response, error) {
202 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
203 }
204
205
206
207 func (client WorkbooksClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
208 err = autorest.Respond(
209 resp,
210 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusNoContent),
211 autorest.ByClosing())
212 result.Response = resp
213 return
214 }
215
216
217
218
219
220 func (client WorkbooksClient) Get(ctx context.Context, resourceGroupName string, resourceName string) (result Workbook, err error) {
221 if tracing.IsEnabled() {
222 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.Get")
223 defer func() {
224 sc := -1
225 if result.Response.Response != nil {
226 sc = result.Response.Response.StatusCode
227 }
228 tracing.EndSpan(ctx, sc, err)
229 }()
230 }
231 if err := validation.Validate([]validation.Validation{
232 {TargetValue: client.SubscriptionID,
233 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
234 {TargetValue: resourceGroupName,
235 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
236 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
237 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, 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 = "2015-05-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 func (client WorkbooksClient) ListByResourceGroup(ctx context.Context, resourceGroupName string, category CategoryType, tags []string, canFetchContent *bool) (result WorkbooksListResult, err error) {
310 if tracing.IsEnabled() {
311 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.ListByResourceGroup")
312 defer func() {
313 sc := -1
314 if result.Response.Response != nil {
315 sc = result.Response.Response.StatusCode
316 }
317 tracing.EndSpan(ctx, sc, err)
318 }()
319 }
320 if err := validation.Validate([]validation.Validation{
321 {TargetValue: client.SubscriptionID,
322 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
323 {TargetValue: resourceGroupName,
324 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
325 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
326 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
327 return result, validation.NewError("insights.WorkbooksClient", "ListByResourceGroup", err.Error())
328 }
329
330 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName, category, tags, canFetchContent)
331 if err != nil {
332 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListByResourceGroup", nil, "Failure preparing request")
333 return
334 }
335
336 resp, err := client.ListByResourceGroupSender(req)
337 if err != nil {
338 result.Response = autorest.Response{Response: resp}
339 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListByResourceGroup", resp, "Failure sending request")
340 return
341 }
342
343 result, err = client.ListByResourceGroupResponder(resp)
344 if err != nil {
345 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "ListByResourceGroup", resp, "Failure responding to request")
346 return
347 }
348
349 return
350 }
351
352
353 func (client WorkbooksClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string, category CategoryType, tags []string, canFetchContent *bool) (*http.Request, error) {
354 pathParameters := map[string]interface{}{
355 "resourceGroupName": autorest.Encode("path", resourceGroupName),
356 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
357 }
358
359 const APIVersion = "2015-05-01"
360 queryParameters := map[string]interface{}{
361 "api-version": APIVersion,
362 "category": autorest.Encode("query", category),
363 }
364 if tags != nil && len(tags) > 0 {
365 queryParameters["tags"] = autorest.Encode("query", tags, ",")
366 }
367 if canFetchContent != nil {
368 queryParameters["canFetchContent"] = autorest.Encode("query", *canFetchContent)
369 }
370
371 preparer := autorest.CreatePreparer(
372 autorest.AsGet(),
373 autorest.WithBaseURL(client.BaseURI),
374 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/workbooks", pathParameters),
375 autorest.WithQueryParameters(queryParameters))
376 return preparer.Prepare((&http.Request{}).WithContext(ctx))
377 }
378
379
380
381 func (client WorkbooksClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
382 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
383 }
384
385
386
387 func (client WorkbooksClient) ListByResourceGroupResponder(resp *http.Response) (result WorkbooksListResult, err error) {
388 err = autorest.Respond(
389 resp,
390 azure.WithErrorUnlessStatusCode(http.StatusOK),
391 autorest.ByUnmarshallingJSON(&result),
392 autorest.ByClosing())
393 result.Response = autorest.Response{Response: resp}
394 return
395 }
396
397
398
399
400
401
402 func (client WorkbooksClient) Update(ctx context.Context, resourceGroupName string, resourceName string, workbookProperties Workbook) (result Workbook, err error) {
403 if tracing.IsEnabled() {
404 ctx = tracing.StartSpan(ctx, fqdn+"/WorkbooksClient.Update")
405 defer func() {
406 sc := -1
407 if result.Response.Response != nil {
408 sc = result.Response.Response.StatusCode
409 }
410 tracing.EndSpan(ctx, sc, err)
411 }()
412 }
413 if err := validation.Validate([]validation.Validation{
414 {TargetValue: client.SubscriptionID,
415 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
416 {TargetValue: resourceGroupName,
417 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
418 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
419 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
420 return result, validation.NewError("insights.WorkbooksClient", "Update", err.Error())
421 }
422
423 req, err := client.UpdatePreparer(ctx, resourceGroupName, resourceName, workbookProperties)
424 if err != nil {
425 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Update", nil, "Failure preparing request")
426 return
427 }
428
429 resp, err := client.UpdateSender(req)
430 if err != nil {
431 result.Response = autorest.Response{Response: resp}
432 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Update", resp, "Failure sending request")
433 return
434 }
435
436 result, err = client.UpdateResponder(resp)
437 if err != nil {
438 err = autorest.NewErrorWithError(err, "insights.WorkbooksClient", "Update", resp, "Failure responding to request")
439 return
440 }
441
442 return
443 }
444
445
446 func (client WorkbooksClient) UpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, workbookProperties Workbook) (*http.Request, error) {
447 pathParameters := map[string]interface{}{
448 "resourceGroupName": autorest.Encode("path", resourceGroupName),
449 "resourceName": autorest.Encode("path", resourceName),
450 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
451 }
452
453 const APIVersion = "2015-05-01"
454 queryParameters := map[string]interface{}{
455 "api-version": APIVersion,
456 }
457
458 preparer := autorest.CreatePreparer(
459 autorest.AsContentType("application/json; charset=utf-8"),
460 autorest.AsPatch(),
461 autorest.WithBaseURL(client.BaseURI),
462 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/workbooks/{resourceName}", pathParameters),
463 autorest.WithJSON(workbookProperties),
464 autorest.WithQueryParameters(queryParameters))
465 return preparer.Prepare((&http.Request{}).WithContext(ctx))
466 }
467
468
469
470 func (client WorkbooksClient) UpdateSender(req *http.Request) (*http.Response, error) {
471 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
472 }
473
474
475
476 func (client WorkbooksClient) UpdateResponder(resp *http.Response) (result Workbook, err error) {
477 err = autorest.Respond(
478 resp,
479 azure.WithErrorUnlessStatusCode(http.StatusOK),
480 autorest.ByUnmarshallingJSON(&result),
481 autorest.ByClosing())
482 result.Response = autorest.Response{Response: resp}
483 return
484 }
485
View as plain text