...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-09-01-preview/datacollection/ruleassociations.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-09-01-preview/datacollection

     1  package datacollection
     2  
     3  // Copyright (c) Microsoft Corporation. All rights reserved.
     4  // Licensed under the MIT License. See License.txt in the project root for license information.
     5  //
     6  // Code generated by Microsoft (R) AutoRest Code Generator.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     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  // RuleAssociationsClient is the monitor Management Client
    19  type RuleAssociationsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewRuleAssociationsClient creates an instance of the RuleAssociationsClient client.
    24  func NewRuleAssociationsClient(subscriptionID string) RuleAssociationsClient {
    25  	return NewRuleAssociationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewRuleAssociationsClientWithBaseURI creates an instance of the RuleAssociationsClient client using a custom
    29  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    30  // stack).
    31  func NewRuleAssociationsClientWithBaseURI(baseURI string, subscriptionID string) RuleAssociationsClient {
    32  	return RuleAssociationsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // Create sends the create request.
    36  // Parameters:
    37  // resourceURI - the identifier of the resource.
    38  // associationName - the name of the association. The name is case insensitive.
    39  // body - the payload
    40  func (client RuleAssociationsClient) Create(ctx context.Context, resourceURI string, associationName string, body *RuleAssociationProxyOnlyResource) (result RuleAssociationProxyOnlyResource, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/RuleAssociationsClient.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("datacollection.RuleAssociationsClient", "Create", err.Error())
    55  	}
    56  
    57  	req, err := client.CreatePreparer(ctx, resourceURI, associationName, body)
    58  	if err != nil {
    59  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "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, "datacollection.RuleAssociationsClient", "Create", resp, "Failure sending request")
    67  		return
    68  	}
    69  
    70  	result, err = client.CreateResponder(resp)
    71  	if err != nil {
    72  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "Create", resp, "Failure responding to request")
    73  		return
    74  	}
    75  
    76  	return
    77  }
    78  
    79  // CreatePreparer prepares the Create request.
    80  func (client RuleAssociationsClient) CreatePreparer(ctx context.Context, resourceURI string, associationName string, body *RuleAssociationProxyOnlyResource) (*http.Request, error) {
    81  	pathParameters := map[string]interface{}{
    82  		"associationName": autorest.Encode("path", associationName),
    83  		"resourceUri":     resourceURI,
    84  	}
    85  
    86  	const APIVersion = "2021-09-01-preview"
    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  // CreateSender sends the Create request. The method will close the
   110  // http.Response Body if it receives an error.
   111  func (client RuleAssociationsClient) CreateSender(req *http.Request) (*http.Response, error) {
   112  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   113  }
   114  
   115  // CreateResponder handles the response to the Create request. The method always
   116  // closes the http.Response Body.
   117  func (client RuleAssociationsClient) CreateResponder(resp *http.Response) (result RuleAssociationProxyOnlyResource, 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  // Delete sends the delete request.
   128  // Parameters:
   129  // resourceURI - the identifier of the resource.
   130  // associationName - the name of the association. The name is case insensitive.
   131  func (client RuleAssociationsClient) Delete(ctx context.Context, resourceURI string, associationName string) (result autorest.Response, err error) {
   132  	if tracing.IsEnabled() {
   133  		ctx = tracing.StartSpan(ctx, fqdn+"/RuleAssociationsClient.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("datacollection.RuleAssociationsClient", "Delete", err.Error())
   146  	}
   147  
   148  	req, err := client.DeletePreparer(ctx, resourceURI, associationName)
   149  	if err != nil {
   150  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "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, "datacollection.RuleAssociationsClient", "Delete", resp, "Failure sending request")
   158  		return
   159  	}
   160  
   161  	result, err = client.DeleteResponder(resp)
   162  	if err != nil {
   163  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "Delete", resp, "Failure responding to request")
   164  		return
   165  	}
   166  
   167  	return
   168  }
   169  
   170  // DeletePreparer prepares the Delete request.
   171  func (client RuleAssociationsClient) 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-09-01-preview"
   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  // DeleteSender sends the Delete request. The method will close the
   191  // http.Response Body if it receives an error.
   192  func (client RuleAssociationsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   193  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   194  }
   195  
   196  // DeleteResponder handles the response to the Delete request. The method always
   197  // closes the http.Response Body.
   198  func (client RuleAssociationsClient) 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  // Get sends the get request.
   208  // Parameters:
   209  // resourceURI - the identifier of the resource.
   210  // associationName - the name of the association. The name is case insensitive.
   211  func (client RuleAssociationsClient) Get(ctx context.Context, resourceURI string, associationName string) (result RuleAssociationProxyOnlyResource, err error) {
   212  	if tracing.IsEnabled() {
   213  		ctx = tracing.StartSpan(ctx, fqdn+"/RuleAssociationsClient.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("datacollection.RuleAssociationsClient", "Get", err.Error())
   226  	}
   227  
   228  	req, err := client.GetPreparer(ctx, resourceURI, associationName)
   229  	if err != nil {
   230  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "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, "datacollection.RuleAssociationsClient", "Get", resp, "Failure sending request")
   238  		return
   239  	}
   240  
   241  	result, err = client.GetResponder(resp)
   242  	if err != nil {
   243  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "Get", resp, "Failure responding to request")
   244  		return
   245  	}
   246  
   247  	return
   248  }
   249  
   250  // GetPreparer prepares the Get request.
   251  func (client RuleAssociationsClient) 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-09-01-preview"
   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  // GetSender sends the Get request. The method will close the
   271  // http.Response Body if it receives an error.
   272  func (client RuleAssociationsClient) GetSender(req *http.Request) (*http.Response, error) {
   273  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   274  }
   275  
   276  // GetResponder handles the response to the Get request. The method always
   277  // closes the http.Response Body.
   278  func (client RuleAssociationsClient) GetResponder(resp *http.Response) (result RuleAssociationProxyOnlyResource, 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  // ListByDataCollectionEndpoint sends the list by data collection endpoint request.
   289  // Parameters:
   290  // resourceGroupName - the name of the resource group. The name is case insensitive.
   291  // dataCollectionEndpointName - the name of the data collection endpoint. The name is case insensitive.
   292  func (client RuleAssociationsClient) ListByDataCollectionEndpoint(ctx context.Context, resourceGroupName string, dataCollectionEndpointName string) (result RuleAssociationProxyOnlyResourceListResultPage, err error) {
   293  	if tracing.IsEnabled() {
   294  		ctx = tracing.StartSpan(ctx, fqdn+"/RuleAssociationsClient.ListByDataCollectionEndpoint")
   295  		defer func() {
   296  			sc := -1
   297  			if result.raporlr.Response.Response != nil {
   298  				sc = result.raporlr.Response.Response.StatusCode
   299  			}
   300  			tracing.EndSpan(ctx, sc, err)
   301  		}()
   302  	}
   303  	if err := validation.Validate([]validation.Validation{
   304  		{TargetValue: client.SubscriptionID,
   305  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   306  		{TargetValue: resourceGroupName,
   307  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   308  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   309  		return result, validation.NewError("datacollection.RuleAssociationsClient", "ListByDataCollectionEndpoint", err.Error())
   310  	}
   311  
   312  	result.fn = client.listByDataCollectionEndpointNextResults
   313  	req, err := client.ListByDataCollectionEndpointPreparer(ctx, resourceGroupName, dataCollectionEndpointName)
   314  	if err != nil {
   315  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "ListByDataCollectionEndpoint", nil, "Failure preparing request")
   316  		return
   317  	}
   318  
   319  	resp, err := client.ListByDataCollectionEndpointSender(req)
   320  	if err != nil {
   321  		result.raporlr.Response = autorest.Response{Response: resp}
   322  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "ListByDataCollectionEndpoint", resp, "Failure sending request")
   323  		return
   324  	}
   325  
   326  	result.raporlr, err = client.ListByDataCollectionEndpointResponder(resp)
   327  	if err != nil {
   328  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "ListByDataCollectionEndpoint", resp, "Failure responding to request")
   329  		return
   330  	}
   331  	if result.raporlr.hasNextLink() && result.raporlr.IsEmpty() {
   332  		err = result.NextWithContext(ctx)
   333  		return
   334  	}
   335  
   336  	return
   337  }
   338  
   339  // ListByDataCollectionEndpointPreparer prepares the ListByDataCollectionEndpoint request.
   340  func (client RuleAssociationsClient) ListByDataCollectionEndpointPreparer(ctx context.Context, resourceGroupName string, dataCollectionEndpointName string) (*http.Request, error) {
   341  	pathParameters := map[string]interface{}{
   342  		"dataCollectionEndpointName": autorest.Encode("path", dataCollectionEndpointName),
   343  		"resourceGroupName":          autorest.Encode("path", resourceGroupName),
   344  		"subscriptionId":             autorest.Encode("path", client.SubscriptionID),
   345  	}
   346  
   347  	const APIVersion = "2021-09-01-preview"
   348  	queryParameters := map[string]interface{}{
   349  		"api-version": APIVersion,
   350  	}
   351  
   352  	preparer := autorest.CreatePreparer(
   353  		autorest.AsGet(),
   354  		autorest.WithBaseURL(client.BaseURI),
   355  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/dataCollectionEndpoints/{dataCollectionEndpointName}/associations", pathParameters),
   356  		autorest.WithQueryParameters(queryParameters))
   357  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   358  }
   359  
   360  // ListByDataCollectionEndpointSender sends the ListByDataCollectionEndpoint request. The method will close the
   361  // http.Response Body if it receives an error.
   362  func (client RuleAssociationsClient) ListByDataCollectionEndpointSender(req *http.Request) (*http.Response, error) {
   363  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   364  }
   365  
   366  // ListByDataCollectionEndpointResponder handles the response to the ListByDataCollectionEndpoint request. The method always
   367  // closes the http.Response Body.
   368  func (client RuleAssociationsClient) ListByDataCollectionEndpointResponder(resp *http.Response) (result RuleAssociationProxyOnlyResourceListResult, err error) {
   369  	err = autorest.Respond(
   370  		resp,
   371  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   372  		autorest.ByUnmarshallingJSON(&result),
   373  		autorest.ByClosing())
   374  	result.Response = autorest.Response{Response: resp}
   375  	return
   376  }
   377  
   378  // listByDataCollectionEndpointNextResults retrieves the next set of results, if any.
   379  func (client RuleAssociationsClient) listByDataCollectionEndpointNextResults(ctx context.Context, lastResults RuleAssociationProxyOnlyResourceListResult) (result RuleAssociationProxyOnlyResourceListResult, err error) {
   380  	req, err := lastResults.ruleAssociationProxyOnlyResourceListResultPreparer(ctx)
   381  	if err != nil {
   382  		return result, autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "listByDataCollectionEndpointNextResults", nil, "Failure preparing next results request")
   383  	}
   384  	if req == nil {
   385  		return
   386  	}
   387  	resp, err := client.ListByDataCollectionEndpointSender(req)
   388  	if err != nil {
   389  		result.Response = autorest.Response{Response: resp}
   390  		return result, autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "listByDataCollectionEndpointNextResults", resp, "Failure sending next results request")
   391  	}
   392  	result, err = client.ListByDataCollectionEndpointResponder(resp)
   393  	if err != nil {
   394  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "listByDataCollectionEndpointNextResults", resp, "Failure responding to next results request")
   395  	}
   396  	return
   397  }
   398  
   399  // ListByDataCollectionEndpointComplete enumerates all values, automatically crossing page boundaries as required.
   400  func (client RuleAssociationsClient) ListByDataCollectionEndpointComplete(ctx context.Context, resourceGroupName string, dataCollectionEndpointName string) (result RuleAssociationProxyOnlyResourceListResultIterator, err error) {
   401  	if tracing.IsEnabled() {
   402  		ctx = tracing.StartSpan(ctx, fqdn+"/RuleAssociationsClient.ListByDataCollectionEndpoint")
   403  		defer func() {
   404  			sc := -1
   405  			if result.Response().Response.Response != nil {
   406  				sc = result.page.Response().Response.Response.StatusCode
   407  			}
   408  			tracing.EndSpan(ctx, sc, err)
   409  		}()
   410  	}
   411  	result.page, err = client.ListByDataCollectionEndpoint(ctx, resourceGroupName, dataCollectionEndpointName)
   412  	return
   413  }
   414  
   415  // ListByResource sends the list by resource request.
   416  // Parameters:
   417  // resourceURI - the identifier of the resource.
   418  func (client RuleAssociationsClient) ListByResource(ctx context.Context, resourceURI string) (result RuleAssociationProxyOnlyResourceListResultPage, err error) {
   419  	if tracing.IsEnabled() {
   420  		ctx = tracing.StartSpan(ctx, fqdn+"/RuleAssociationsClient.ListByResource")
   421  		defer func() {
   422  			sc := -1
   423  			if result.raporlr.Response.Response != nil {
   424  				sc = result.raporlr.Response.Response.StatusCode
   425  			}
   426  			tracing.EndSpan(ctx, sc, err)
   427  		}()
   428  	}
   429  	if err := validation.Validate([]validation.Validation{
   430  		{TargetValue: resourceURI,
   431  			Constraints: []validation.Constraint{{Target: "resourceURI", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   432  		return result, validation.NewError("datacollection.RuleAssociationsClient", "ListByResource", err.Error())
   433  	}
   434  
   435  	result.fn = client.listByResourceNextResults
   436  	req, err := client.ListByResourcePreparer(ctx, resourceURI)
   437  	if err != nil {
   438  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "ListByResource", nil, "Failure preparing request")
   439  		return
   440  	}
   441  
   442  	resp, err := client.ListByResourceSender(req)
   443  	if err != nil {
   444  		result.raporlr.Response = autorest.Response{Response: resp}
   445  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "ListByResource", resp, "Failure sending request")
   446  		return
   447  	}
   448  
   449  	result.raporlr, err = client.ListByResourceResponder(resp)
   450  	if err != nil {
   451  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "ListByResource", resp, "Failure responding to request")
   452  		return
   453  	}
   454  	if result.raporlr.hasNextLink() && result.raporlr.IsEmpty() {
   455  		err = result.NextWithContext(ctx)
   456  		return
   457  	}
   458  
   459  	return
   460  }
   461  
   462  // ListByResourcePreparer prepares the ListByResource request.
   463  func (client RuleAssociationsClient) ListByResourcePreparer(ctx context.Context, resourceURI string) (*http.Request, error) {
   464  	pathParameters := map[string]interface{}{
   465  		"resourceUri": resourceURI,
   466  	}
   467  
   468  	const APIVersion = "2021-09-01-preview"
   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("/{resourceUri}/providers/Microsoft.Insights/dataCollectionRuleAssociations", pathParameters),
   477  		autorest.WithQueryParameters(queryParameters))
   478  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   479  }
   480  
   481  // ListByResourceSender sends the ListByResource request. The method will close the
   482  // http.Response Body if it receives an error.
   483  func (client RuleAssociationsClient) ListByResourceSender(req *http.Request) (*http.Response, error) {
   484  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   485  }
   486  
   487  // ListByResourceResponder handles the response to the ListByResource request. The method always
   488  // closes the http.Response Body.
   489  func (client RuleAssociationsClient) ListByResourceResponder(resp *http.Response) (result RuleAssociationProxyOnlyResourceListResult, 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  // listByResourceNextResults retrieves the next set of results, if any.
   500  func (client RuleAssociationsClient) listByResourceNextResults(ctx context.Context, lastResults RuleAssociationProxyOnlyResourceListResult) (result RuleAssociationProxyOnlyResourceListResult, err error) {
   501  	req, err := lastResults.ruleAssociationProxyOnlyResourceListResultPreparer(ctx)
   502  	if err != nil {
   503  		return result, autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "listByResourceNextResults", nil, "Failure preparing next results request")
   504  	}
   505  	if req == nil {
   506  		return
   507  	}
   508  	resp, err := client.ListByResourceSender(req)
   509  	if err != nil {
   510  		result.Response = autorest.Response{Response: resp}
   511  		return result, autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "listByResourceNextResults", resp, "Failure sending next results request")
   512  	}
   513  	result, err = client.ListByResourceResponder(resp)
   514  	if err != nil {
   515  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "listByResourceNextResults", resp, "Failure responding to next results request")
   516  	}
   517  	return
   518  }
   519  
   520  // ListByResourceComplete enumerates all values, automatically crossing page boundaries as required.
   521  func (client RuleAssociationsClient) ListByResourceComplete(ctx context.Context, resourceURI string) (result RuleAssociationProxyOnlyResourceListResultIterator, err error) {
   522  	if tracing.IsEnabled() {
   523  		ctx = tracing.StartSpan(ctx, fqdn+"/RuleAssociationsClient.ListByResource")
   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.ListByResource(ctx, resourceURI)
   533  	return
   534  }
   535  
   536  // ListByRule sends the list by rule request.
   537  // Parameters:
   538  // resourceGroupName - the name of the resource group. The name is case insensitive.
   539  // dataCollectionRuleName - the name of the data collection rule. The name is case insensitive.
   540  func (client RuleAssociationsClient) ListByRule(ctx context.Context, resourceGroupName string, dataCollectionRuleName string) (result RuleAssociationProxyOnlyResourceListResultPage, err error) {
   541  	if tracing.IsEnabled() {
   542  		ctx = tracing.StartSpan(ctx, fqdn+"/RuleAssociationsClient.ListByRule")
   543  		defer func() {
   544  			sc := -1
   545  			if result.raporlr.Response.Response != nil {
   546  				sc = result.raporlr.Response.Response.StatusCode
   547  			}
   548  			tracing.EndSpan(ctx, sc, err)
   549  		}()
   550  	}
   551  	if err := validation.Validate([]validation.Validation{
   552  		{TargetValue: client.SubscriptionID,
   553  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   554  		{TargetValue: resourceGroupName,
   555  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   556  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   557  		return result, validation.NewError("datacollection.RuleAssociationsClient", "ListByRule", err.Error())
   558  	}
   559  
   560  	result.fn = client.listByRuleNextResults
   561  	req, err := client.ListByRulePreparer(ctx, resourceGroupName, dataCollectionRuleName)
   562  	if err != nil {
   563  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "ListByRule", nil, "Failure preparing request")
   564  		return
   565  	}
   566  
   567  	resp, err := client.ListByRuleSender(req)
   568  	if err != nil {
   569  		result.raporlr.Response = autorest.Response{Response: resp}
   570  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "ListByRule", resp, "Failure sending request")
   571  		return
   572  	}
   573  
   574  	result.raporlr, err = client.ListByRuleResponder(resp)
   575  	if err != nil {
   576  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "ListByRule", resp, "Failure responding to request")
   577  		return
   578  	}
   579  	if result.raporlr.hasNextLink() && result.raporlr.IsEmpty() {
   580  		err = result.NextWithContext(ctx)
   581  		return
   582  	}
   583  
   584  	return
   585  }
   586  
   587  // ListByRulePreparer prepares the ListByRule request.
   588  func (client RuleAssociationsClient) ListByRulePreparer(ctx context.Context, resourceGroupName string, dataCollectionRuleName string) (*http.Request, error) {
   589  	pathParameters := map[string]interface{}{
   590  		"dataCollectionRuleName": autorest.Encode("path", dataCollectionRuleName),
   591  		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
   592  		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
   593  	}
   594  
   595  	const APIVersion = "2021-09-01-preview"
   596  	queryParameters := map[string]interface{}{
   597  		"api-version": APIVersion,
   598  	}
   599  
   600  	preparer := autorest.CreatePreparer(
   601  		autorest.AsGet(),
   602  		autorest.WithBaseURL(client.BaseURI),
   603  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/dataCollectionRules/{dataCollectionRuleName}/associations", pathParameters),
   604  		autorest.WithQueryParameters(queryParameters))
   605  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   606  }
   607  
   608  // ListByRuleSender sends the ListByRule request. The method will close the
   609  // http.Response Body if it receives an error.
   610  func (client RuleAssociationsClient) ListByRuleSender(req *http.Request) (*http.Response, error) {
   611  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   612  }
   613  
   614  // ListByRuleResponder handles the response to the ListByRule request. The method always
   615  // closes the http.Response Body.
   616  func (client RuleAssociationsClient) ListByRuleResponder(resp *http.Response) (result RuleAssociationProxyOnlyResourceListResult, err error) {
   617  	err = autorest.Respond(
   618  		resp,
   619  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   620  		autorest.ByUnmarshallingJSON(&result),
   621  		autorest.ByClosing())
   622  	result.Response = autorest.Response{Response: resp}
   623  	return
   624  }
   625  
   626  // listByRuleNextResults retrieves the next set of results, if any.
   627  func (client RuleAssociationsClient) listByRuleNextResults(ctx context.Context, lastResults RuleAssociationProxyOnlyResourceListResult) (result RuleAssociationProxyOnlyResourceListResult, err error) {
   628  	req, err := lastResults.ruleAssociationProxyOnlyResourceListResultPreparer(ctx)
   629  	if err != nil {
   630  		return result, autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "listByRuleNextResults", nil, "Failure preparing next results request")
   631  	}
   632  	if req == nil {
   633  		return
   634  	}
   635  	resp, err := client.ListByRuleSender(req)
   636  	if err != nil {
   637  		result.Response = autorest.Response{Response: resp}
   638  		return result, autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "listByRuleNextResults", resp, "Failure sending next results request")
   639  	}
   640  	result, err = client.ListByRuleResponder(resp)
   641  	if err != nil {
   642  		err = autorest.NewErrorWithError(err, "datacollection.RuleAssociationsClient", "listByRuleNextResults", resp, "Failure responding to next results request")
   643  	}
   644  	return
   645  }
   646  
   647  // ListByRuleComplete enumerates all values, automatically crossing page boundaries as required.
   648  func (client RuleAssociationsClient) ListByRuleComplete(ctx context.Context, resourceGroupName string, dataCollectionRuleName string) (result RuleAssociationProxyOnlyResourceListResultIterator, err error) {
   649  	if tracing.IsEnabled() {
   650  		ctx = tracing.StartSpan(ctx, fqdn+"/RuleAssociationsClient.ListByRule")
   651  		defer func() {
   652  			sc := -1
   653  			if result.Response().Response.Response != nil {
   654  				sc = result.page.Response().Response.Response.StatusCode
   655  			}
   656  			tracing.EndSpan(ctx, sc, err)
   657  		}()
   658  	}
   659  	result.page, err = client.ListByRule(ctx, resourceGroupName, dataCollectionRuleName)
   660  	return
   661  }
   662  

View as plain text