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