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