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 DataCollectionRuleAssociationsClient struct {
20 BaseClient
21 }
22
23
24 func NewDataCollectionRuleAssociationsClient(subscriptionID string) DataCollectionRuleAssociationsClient {
25 return NewDataCollectionRuleAssociationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30
31 func NewDataCollectionRuleAssociationsClientWithBaseURI(baseURI string, subscriptionID string) DataCollectionRuleAssociationsClient {
32 return DataCollectionRuleAssociationsClient{NewWithBaseURI(baseURI, subscriptionID)}
33 }
34
35
36
37
38
39
40 func (client DataCollectionRuleAssociationsClient) Create(ctx context.Context, resourceURI string, associationName string, body *DataCollectionRuleAssociationProxyOnlyResource) (result DataCollectionRuleAssociationProxyOnlyResource, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/DataCollectionRuleAssociationsClient.Create")
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: resourceURI,
53 Constraints: []validation.Constraint{{Target: "resourceURI", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
54 return result, validation.NewError("insights.DataCollectionRuleAssociationsClient", "Create", err.Error())
55 }
56
57 req, err := client.CreatePreparer(ctx, resourceURI, associationName, body)
58 if err != nil {
59 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "Create", nil, "Failure preparing request")
60 return
61 }
62
63 resp, err := client.CreateSender(req)
64 if err != nil {
65 result.Response = autorest.Response{Response: resp}
66 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "Create", resp, "Failure sending request")
67 return
68 }
69
70 result, err = client.CreateResponder(resp)
71 if err != nil {
72 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "Create", resp, "Failure responding to request")
73 return
74 }
75
76 return
77 }
78
79
80 func (client DataCollectionRuleAssociationsClient) CreatePreparer(ctx context.Context, resourceURI string, associationName string, body *DataCollectionRuleAssociationProxyOnlyResource) (*http.Request, error) {
81 pathParameters := map[string]interface{}{
82 "associationName": autorest.Encode("path", associationName),
83 "resourceUri": resourceURI,
84 }
85
86 const APIVersion = "2021-04-01"
87 queryParameters := map[string]interface{}{
88 "api-version": APIVersion,
89 }
90
91 body.ID = nil
92 body.Name = nil
93 body.Type = nil
94 body.Etag = nil
95 body.SystemData = nil
96 preparer := autorest.CreatePreparer(
97 autorest.AsContentType("application/json; charset=utf-8"),
98 autorest.AsPut(),
99 autorest.WithBaseURL(client.BaseURI),
100 autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Insights/dataCollectionRuleAssociations/{associationName}", pathParameters),
101 autorest.WithQueryParameters(queryParameters))
102 if body != nil {
103 preparer = autorest.DecoratePreparer(preparer,
104 autorest.WithJSON(body))
105 }
106 return preparer.Prepare((&http.Request{}).WithContext(ctx))
107 }
108
109
110
111 func (client DataCollectionRuleAssociationsClient) CreateSender(req *http.Request) (*http.Response, error) {
112 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
113 }
114
115
116
117 func (client DataCollectionRuleAssociationsClient) CreateResponder(resp *http.Response) (result DataCollectionRuleAssociationProxyOnlyResource, err error) {
118 err = autorest.Respond(
119 resp,
120 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
121 autorest.ByUnmarshallingJSON(&result),
122 autorest.ByClosing())
123 result.Response = autorest.Response{Response: resp}
124 return
125 }
126
127
128
129
130
131 func (client DataCollectionRuleAssociationsClient) Delete(ctx context.Context, resourceURI string, associationName string) (result autorest.Response, err error) {
132 if tracing.IsEnabled() {
133 ctx = tracing.StartSpan(ctx, fqdn+"/DataCollectionRuleAssociationsClient.Delete")
134 defer func() {
135 sc := -1
136 if result.Response != nil {
137 sc = result.Response.StatusCode
138 }
139 tracing.EndSpan(ctx, sc, err)
140 }()
141 }
142 if err := validation.Validate([]validation.Validation{
143 {TargetValue: resourceURI,
144 Constraints: []validation.Constraint{{Target: "resourceURI", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
145 return result, validation.NewError("insights.DataCollectionRuleAssociationsClient", "Delete", err.Error())
146 }
147
148 req, err := client.DeletePreparer(ctx, resourceURI, associationName)
149 if err != nil {
150 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "Delete", nil, "Failure preparing request")
151 return
152 }
153
154 resp, err := client.DeleteSender(req)
155 if err != nil {
156 result.Response = resp
157 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "Delete", resp, "Failure sending request")
158 return
159 }
160
161 result, err = client.DeleteResponder(resp)
162 if err != nil {
163 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "Delete", resp, "Failure responding to request")
164 return
165 }
166
167 return
168 }
169
170
171 func (client DataCollectionRuleAssociationsClient) DeletePreparer(ctx context.Context, resourceURI string, associationName string) (*http.Request, error) {
172 pathParameters := map[string]interface{}{
173 "associationName": autorest.Encode("path", associationName),
174 "resourceUri": resourceURI,
175 }
176
177 const APIVersion = "2021-04-01"
178 queryParameters := map[string]interface{}{
179 "api-version": APIVersion,
180 }
181
182 preparer := autorest.CreatePreparer(
183 autorest.AsDelete(),
184 autorest.WithBaseURL(client.BaseURI),
185 autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Insights/dataCollectionRuleAssociations/{associationName}", pathParameters),
186 autorest.WithQueryParameters(queryParameters))
187 return preparer.Prepare((&http.Request{}).WithContext(ctx))
188 }
189
190
191
192 func (client DataCollectionRuleAssociationsClient) DeleteSender(req *http.Request) (*http.Response, error) {
193 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
194 }
195
196
197
198 func (client DataCollectionRuleAssociationsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
199 err = autorest.Respond(
200 resp,
201 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
202 autorest.ByClosing())
203 result.Response = resp
204 return
205 }
206
207
208
209
210
211 func (client DataCollectionRuleAssociationsClient) Get(ctx context.Context, resourceURI string, associationName string) (result DataCollectionRuleAssociationProxyOnlyResource, err error) {
212 if tracing.IsEnabled() {
213 ctx = tracing.StartSpan(ctx, fqdn+"/DataCollectionRuleAssociationsClient.Get")
214 defer func() {
215 sc := -1
216 if result.Response.Response != nil {
217 sc = result.Response.Response.StatusCode
218 }
219 tracing.EndSpan(ctx, sc, err)
220 }()
221 }
222 if err := validation.Validate([]validation.Validation{
223 {TargetValue: resourceURI,
224 Constraints: []validation.Constraint{{Target: "resourceURI", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
225 return result, validation.NewError("insights.DataCollectionRuleAssociationsClient", "Get", err.Error())
226 }
227
228 req, err := client.GetPreparer(ctx, resourceURI, associationName)
229 if err != nil {
230 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "Get", nil, "Failure preparing request")
231 return
232 }
233
234 resp, err := client.GetSender(req)
235 if err != nil {
236 result.Response = autorest.Response{Response: resp}
237 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "Get", resp, "Failure sending request")
238 return
239 }
240
241 result, err = client.GetResponder(resp)
242 if err != nil {
243 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "Get", resp, "Failure responding to request")
244 return
245 }
246
247 return
248 }
249
250
251 func (client DataCollectionRuleAssociationsClient) GetPreparer(ctx context.Context, resourceURI string, associationName string) (*http.Request, error) {
252 pathParameters := map[string]interface{}{
253 "associationName": autorest.Encode("path", associationName),
254 "resourceUri": resourceURI,
255 }
256
257 const APIVersion = "2021-04-01"
258 queryParameters := map[string]interface{}{
259 "api-version": APIVersion,
260 }
261
262 preparer := autorest.CreatePreparer(
263 autorest.AsGet(),
264 autorest.WithBaseURL(client.BaseURI),
265 autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Insights/dataCollectionRuleAssociations/{associationName}", pathParameters),
266 autorest.WithQueryParameters(queryParameters))
267 return preparer.Prepare((&http.Request{}).WithContext(ctx))
268 }
269
270
271
272 func (client DataCollectionRuleAssociationsClient) GetSender(req *http.Request) (*http.Response, error) {
273 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
274 }
275
276
277
278 func (client DataCollectionRuleAssociationsClient) GetResponder(resp *http.Response) (result DataCollectionRuleAssociationProxyOnlyResource, err error) {
279 err = autorest.Respond(
280 resp,
281 azure.WithErrorUnlessStatusCode(http.StatusOK),
282 autorest.ByUnmarshallingJSON(&result),
283 autorest.ByClosing())
284 result.Response = autorest.Response{Response: resp}
285 return
286 }
287
288
289
290
291 func (client DataCollectionRuleAssociationsClient) ListByResource(ctx context.Context, resourceURI string) (result DataCollectionRuleAssociationProxyOnlyResourceListResultPage, err error) {
292 if tracing.IsEnabled() {
293 ctx = tracing.StartSpan(ctx, fqdn+"/DataCollectionRuleAssociationsClient.ListByResource")
294 defer func() {
295 sc := -1
296 if result.dcraporlr.Response.Response != nil {
297 sc = result.dcraporlr.Response.Response.StatusCode
298 }
299 tracing.EndSpan(ctx, sc, err)
300 }()
301 }
302 if err := validation.Validate([]validation.Validation{
303 {TargetValue: resourceURI,
304 Constraints: []validation.Constraint{{Target: "resourceURI", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
305 return result, validation.NewError("insights.DataCollectionRuleAssociationsClient", "ListByResource", err.Error())
306 }
307
308 result.fn = client.listByResourceNextResults
309 req, err := client.ListByResourcePreparer(ctx, resourceURI)
310 if err != nil {
311 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "ListByResource", nil, "Failure preparing request")
312 return
313 }
314
315 resp, err := client.ListByResourceSender(req)
316 if err != nil {
317 result.dcraporlr.Response = autorest.Response{Response: resp}
318 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "ListByResource", resp, "Failure sending request")
319 return
320 }
321
322 result.dcraporlr, err = client.ListByResourceResponder(resp)
323 if err != nil {
324 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "ListByResource", resp, "Failure responding to request")
325 return
326 }
327 if result.dcraporlr.hasNextLink() && result.dcraporlr.IsEmpty() {
328 err = result.NextWithContext(ctx)
329 return
330 }
331
332 return
333 }
334
335
336 func (client DataCollectionRuleAssociationsClient) ListByResourcePreparer(ctx context.Context, resourceURI string) (*http.Request, error) {
337 pathParameters := map[string]interface{}{
338 "resourceUri": resourceURI,
339 }
340
341 const APIVersion = "2021-04-01"
342 queryParameters := map[string]interface{}{
343 "api-version": APIVersion,
344 }
345
346 preparer := autorest.CreatePreparer(
347 autorest.AsGet(),
348 autorest.WithBaseURL(client.BaseURI),
349 autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Insights/dataCollectionRuleAssociations", pathParameters),
350 autorest.WithQueryParameters(queryParameters))
351 return preparer.Prepare((&http.Request{}).WithContext(ctx))
352 }
353
354
355
356 func (client DataCollectionRuleAssociationsClient) ListByResourceSender(req *http.Request) (*http.Response, error) {
357 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
358 }
359
360
361
362 func (client DataCollectionRuleAssociationsClient) ListByResourceResponder(resp *http.Response) (result DataCollectionRuleAssociationProxyOnlyResourceListResult, err error) {
363 err = autorest.Respond(
364 resp,
365 azure.WithErrorUnlessStatusCode(http.StatusOK),
366 autorest.ByUnmarshallingJSON(&result),
367 autorest.ByClosing())
368 result.Response = autorest.Response{Response: resp}
369 return
370 }
371
372
373 func (client DataCollectionRuleAssociationsClient) listByResourceNextResults(ctx context.Context, lastResults DataCollectionRuleAssociationProxyOnlyResourceListResult) (result DataCollectionRuleAssociationProxyOnlyResourceListResult, err error) {
374 req, err := lastResults.dataCollectionRuleAssociationProxyOnlyResourceListResultPreparer(ctx)
375 if err != nil {
376 return result, autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "listByResourceNextResults", nil, "Failure preparing next results request")
377 }
378 if req == nil {
379 return
380 }
381 resp, err := client.ListByResourceSender(req)
382 if err != nil {
383 result.Response = autorest.Response{Response: resp}
384 return result, autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "listByResourceNextResults", resp, "Failure sending next results request")
385 }
386 result, err = client.ListByResourceResponder(resp)
387 if err != nil {
388 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "listByResourceNextResults", resp, "Failure responding to next results request")
389 }
390 return
391 }
392
393
394 func (client DataCollectionRuleAssociationsClient) ListByResourceComplete(ctx context.Context, resourceURI string) (result DataCollectionRuleAssociationProxyOnlyResourceListResultIterator, err error) {
395 if tracing.IsEnabled() {
396 ctx = tracing.StartSpan(ctx, fqdn+"/DataCollectionRuleAssociationsClient.ListByResource")
397 defer func() {
398 sc := -1
399 if result.Response().Response.Response != nil {
400 sc = result.page.Response().Response.Response.StatusCode
401 }
402 tracing.EndSpan(ctx, sc, err)
403 }()
404 }
405 result.page, err = client.ListByResource(ctx, resourceURI)
406 return
407 }
408
409
410
411
412
413 func (client DataCollectionRuleAssociationsClient) ListByRule(ctx context.Context, resourceGroupName string, dataCollectionRuleName string) (result DataCollectionRuleAssociationProxyOnlyResourceListResultPage, err error) {
414 if tracing.IsEnabled() {
415 ctx = tracing.StartSpan(ctx, fqdn+"/DataCollectionRuleAssociationsClient.ListByRule")
416 defer func() {
417 sc := -1
418 if result.dcraporlr.Response.Response != nil {
419 sc = result.dcraporlr.Response.Response.StatusCode
420 }
421 tracing.EndSpan(ctx, sc, err)
422 }()
423 }
424 if err := validation.Validate([]validation.Validation{
425 {TargetValue: client.SubscriptionID,
426 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
427 {TargetValue: resourceGroupName,
428 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
429 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
430 return result, validation.NewError("insights.DataCollectionRuleAssociationsClient", "ListByRule", err.Error())
431 }
432
433 result.fn = client.listByRuleNextResults
434 req, err := client.ListByRulePreparer(ctx, resourceGroupName, dataCollectionRuleName)
435 if err != nil {
436 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "ListByRule", nil, "Failure preparing request")
437 return
438 }
439
440 resp, err := client.ListByRuleSender(req)
441 if err != nil {
442 result.dcraporlr.Response = autorest.Response{Response: resp}
443 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "ListByRule", resp, "Failure sending request")
444 return
445 }
446
447 result.dcraporlr, err = client.ListByRuleResponder(resp)
448 if err != nil {
449 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "ListByRule", resp, "Failure responding to request")
450 return
451 }
452 if result.dcraporlr.hasNextLink() && result.dcraporlr.IsEmpty() {
453 err = result.NextWithContext(ctx)
454 return
455 }
456
457 return
458 }
459
460
461 func (client DataCollectionRuleAssociationsClient) ListByRulePreparer(ctx context.Context, resourceGroupName string, dataCollectionRuleName string) (*http.Request, error) {
462 pathParameters := map[string]interface{}{
463 "dataCollectionRuleName": autorest.Encode("path", dataCollectionRuleName),
464 "resourceGroupName": autorest.Encode("path", resourceGroupName),
465 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
466 }
467
468 const APIVersion = "2021-04-01"
469 queryParameters := map[string]interface{}{
470 "api-version": APIVersion,
471 }
472
473 preparer := autorest.CreatePreparer(
474 autorest.AsGet(),
475 autorest.WithBaseURL(client.BaseURI),
476 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/dataCollectionRules/{dataCollectionRuleName}/associations", pathParameters),
477 autorest.WithQueryParameters(queryParameters))
478 return preparer.Prepare((&http.Request{}).WithContext(ctx))
479 }
480
481
482
483 func (client DataCollectionRuleAssociationsClient) ListByRuleSender(req *http.Request) (*http.Response, error) {
484 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
485 }
486
487
488
489 func (client DataCollectionRuleAssociationsClient) ListByRuleResponder(resp *http.Response) (result DataCollectionRuleAssociationProxyOnlyResourceListResult, 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
499
500 func (client DataCollectionRuleAssociationsClient) listByRuleNextResults(ctx context.Context, lastResults DataCollectionRuleAssociationProxyOnlyResourceListResult) (result DataCollectionRuleAssociationProxyOnlyResourceListResult, err error) {
501 req, err := lastResults.dataCollectionRuleAssociationProxyOnlyResourceListResultPreparer(ctx)
502 if err != nil {
503 return result, autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "listByRuleNextResults", nil, "Failure preparing next results request")
504 }
505 if req == nil {
506 return
507 }
508 resp, err := client.ListByRuleSender(req)
509 if err != nil {
510 result.Response = autorest.Response{Response: resp}
511 return result, autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "listByRuleNextResults", resp, "Failure sending next results request")
512 }
513 result, err = client.ListByRuleResponder(resp)
514 if err != nil {
515 err = autorest.NewErrorWithError(err, "insights.DataCollectionRuleAssociationsClient", "listByRuleNextResults", resp, "Failure responding to next results request")
516 }
517 return
518 }
519
520
521 func (client DataCollectionRuleAssociationsClient) ListByRuleComplete(ctx context.Context, resourceGroupName string, dataCollectionRuleName string) (result DataCollectionRuleAssociationProxyOnlyResourceListResultIterator, err error) {
522 if tracing.IsEnabled() {
523 ctx = tracing.StartSpan(ctx, fqdn+"/DataCollectionRuleAssociationsClient.ListByRule")
524 defer func() {
525 sc := -1
526 if result.Response().Response.Response != nil {
527 sc = result.page.Response().Response.Response.StatusCode
528 }
529 tracing.EndSpan(ctx, sc, err)
530 }()
531 }
532 result.page, err = client.ListByRule(ctx, resourceGroupName, dataCollectionRuleName)
533 return
534 }
535
View as plain text