...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-05-01-preview/diagnostics/privatelinkscopes.go

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

     1  package diagnostics
     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  // PrivateLinkScopesClient is the monitor Management Client
    19  type PrivateLinkScopesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewPrivateLinkScopesClient creates an instance of the PrivateLinkScopesClient client.
    24  func NewPrivateLinkScopesClient(subscriptionID string) PrivateLinkScopesClient {
    25  	return NewPrivateLinkScopesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewPrivateLinkScopesClientWithBaseURI creates an instance of the PrivateLinkScopesClient 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 NewPrivateLinkScopesClientWithBaseURI(baseURI string, subscriptionID string) PrivateLinkScopesClient {
    32  	return PrivateLinkScopesClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // CreateOrUpdate creates (or updates) a Azure Monitor PrivateLinkScope. Note: You cannot specify a different value for
    36  // InstrumentationKey nor AppId in the Put operation.
    37  // Parameters:
    38  // resourceGroupName - the name of the resource group. The name is case insensitive.
    39  // scopeName - the name of the Azure Monitor PrivateLinkScope resource.
    40  // azureMonitorPrivateLinkScopePayload - properties that need to be specified to create or update a Azure
    41  // Monitor PrivateLinkScope.
    42  func (client PrivateLinkScopesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, scopeName string, azureMonitorPrivateLinkScopePayload AzureMonitorPrivateLinkScope) (result AzureMonitorPrivateLinkScope, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopesClient.CreateOrUpdate")
    45  		defer func() {
    46  			sc := -1
    47  			if result.Response.Response != nil {
    48  				sc = result.Response.Response.StatusCode
    49  			}
    50  			tracing.EndSpan(ctx, sc, err)
    51  		}()
    52  	}
    53  	if err := validation.Validate([]validation.Validation{
    54  		{TargetValue: resourceGroupName,
    55  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    56  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    57  		{TargetValue: client.SubscriptionID,
    58  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    59  		{TargetValue: azureMonitorPrivateLinkScopePayload,
    60  			Constraints: []validation.Constraint{{Target: "azureMonitorPrivateLinkScopePayload.AzureMonitorPrivateLinkScopeProperties", Name: validation.Null, Rule: true,
    61  				Chain: []validation.Constraint{{Target: "azureMonitorPrivateLinkScopePayload.AzureMonitorPrivateLinkScopeProperties.AccessModeSettings", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
    62  		return result, validation.NewError("diagnostics.PrivateLinkScopesClient", "CreateOrUpdate", err.Error())
    63  	}
    64  
    65  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, scopeName, azureMonitorPrivateLinkScopePayload)
    66  	if err != nil {
    67  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "CreateOrUpdate", nil, "Failure preparing request")
    68  		return
    69  	}
    70  
    71  	resp, err := client.CreateOrUpdateSender(req)
    72  	if err != nil {
    73  		result.Response = autorest.Response{Response: resp}
    74  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "CreateOrUpdate", resp, "Failure sending request")
    75  		return
    76  	}
    77  
    78  	result, err = client.CreateOrUpdateResponder(resp)
    79  	if err != nil {
    80  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "CreateOrUpdate", resp, "Failure responding to request")
    81  		return
    82  	}
    83  
    84  	return
    85  }
    86  
    87  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    88  func (client PrivateLinkScopesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, scopeName string, azureMonitorPrivateLinkScopePayload AzureMonitorPrivateLinkScope) (*http.Request, error) {
    89  	pathParameters := map[string]interface{}{
    90  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    91  		"scopeName":         autorest.Encode("path", scopeName),
    92  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    93  	}
    94  
    95  	const APIVersion = "2021-07-01-preview"
    96  	queryParameters := map[string]interface{}{
    97  		"api-version": APIVersion,
    98  	}
    99  
   100  	azureMonitorPrivateLinkScopePayload.SystemData = nil
   101  	preparer := autorest.CreatePreparer(
   102  		autorest.AsContentType("application/json; charset=utf-8"),
   103  		autorest.AsPut(),
   104  		autorest.WithBaseURL(client.BaseURI),
   105  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/privateLinkScopes/{scopeName}", pathParameters),
   106  		autorest.WithJSON(azureMonitorPrivateLinkScopePayload),
   107  		autorest.WithQueryParameters(queryParameters))
   108  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   109  }
   110  
   111  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   112  // http.Response Body if it receives an error.
   113  func (client PrivateLinkScopesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   114  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   115  }
   116  
   117  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   118  // closes the http.Response Body.
   119  func (client PrivateLinkScopesClient) CreateOrUpdateResponder(resp *http.Response) (result AzureMonitorPrivateLinkScope, err error) {
   120  	err = autorest.Respond(
   121  		resp,
   122  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   123  		autorest.ByUnmarshallingJSON(&result),
   124  		autorest.ByClosing())
   125  	result.Response = autorest.Response{Response: resp}
   126  	return
   127  }
   128  
   129  // Delete deletes a Azure Monitor PrivateLinkScope.
   130  // Parameters:
   131  // resourceGroupName - the name of the resource group. The name is case insensitive.
   132  // scopeName - the name of the Azure Monitor PrivateLinkScope resource.
   133  func (client PrivateLinkScopesClient) Delete(ctx context.Context, resourceGroupName string, scopeName string) (result PrivateLinkScopesDeleteFuture, err error) {
   134  	if tracing.IsEnabled() {
   135  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopesClient.Delete")
   136  		defer func() {
   137  			sc := -1
   138  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   139  				sc = result.FutureAPI.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("diagnostics.PrivateLinkScopesClient", "Delete", err.Error())
   151  	}
   152  
   153  	req, err := client.DeletePreparer(ctx, resourceGroupName, scopeName)
   154  	if err != nil {
   155  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "Delete", nil, "Failure preparing request")
   156  		return
   157  	}
   158  
   159  	result, err = client.DeleteSender(req)
   160  	if err != nil {
   161  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "Delete", result.Response(), "Failure sending request")
   162  		return
   163  	}
   164  
   165  	return
   166  }
   167  
   168  // DeletePreparer prepares the Delete request.
   169  func (client PrivateLinkScopesClient) DeletePreparer(ctx context.Context, resourceGroupName string, scopeName string) (*http.Request, error) {
   170  	pathParameters := map[string]interface{}{
   171  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   172  		"scopeName":         autorest.Encode("path", scopeName),
   173  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   174  	}
   175  
   176  	const APIVersion = "2021-07-01-preview"
   177  	queryParameters := map[string]interface{}{
   178  		"api-version": APIVersion,
   179  	}
   180  
   181  	preparer := autorest.CreatePreparer(
   182  		autorest.AsDelete(),
   183  		autorest.WithBaseURL(client.BaseURI),
   184  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/privateLinkScopes/{scopeName}", pathParameters),
   185  		autorest.WithQueryParameters(queryParameters))
   186  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   187  }
   188  
   189  // DeleteSender sends the Delete request. The method will close the
   190  // http.Response Body if it receives an error.
   191  func (client PrivateLinkScopesClient) DeleteSender(req *http.Request) (future PrivateLinkScopesDeleteFuture, err error) {
   192  	var resp *http.Response
   193  	future.FutureAPI = &azure.Future{}
   194  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   195  	if err != nil {
   196  		return
   197  	}
   198  	var azf azure.Future
   199  	azf, err = azure.NewFutureFromResponse(resp)
   200  	future.FutureAPI = &azf
   201  	future.Result = future.result
   202  	return
   203  }
   204  
   205  // DeleteResponder handles the response to the Delete request. The method always
   206  // closes the http.Response Body.
   207  func (client PrivateLinkScopesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   208  	err = autorest.Respond(
   209  		resp,
   210  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   211  		autorest.ByClosing())
   212  	result.Response = resp
   213  	return
   214  }
   215  
   216  // Get returns a Azure Monitor PrivateLinkScope.
   217  // Parameters:
   218  // resourceGroupName - the name of the resource group. The name is case insensitive.
   219  // scopeName - the name of the Azure Monitor PrivateLinkScope resource.
   220  func (client PrivateLinkScopesClient) Get(ctx context.Context, resourceGroupName string, scopeName string) (result AzureMonitorPrivateLinkScope, err error) {
   221  	if tracing.IsEnabled() {
   222  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopesClient.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: resourceGroupName,
   233  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   234  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   235  		{TargetValue: client.SubscriptionID,
   236  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   237  		return result, validation.NewError("diagnostics.PrivateLinkScopesClient", "Get", err.Error())
   238  	}
   239  
   240  	req, err := client.GetPreparer(ctx, resourceGroupName, scopeName)
   241  	if err != nil {
   242  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "Get", nil, "Failure preparing request")
   243  		return
   244  	}
   245  
   246  	resp, err := client.GetSender(req)
   247  	if err != nil {
   248  		result.Response = autorest.Response{Response: resp}
   249  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "Get", resp, "Failure sending request")
   250  		return
   251  	}
   252  
   253  	result, err = client.GetResponder(resp)
   254  	if err != nil {
   255  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "Get", resp, "Failure responding to request")
   256  		return
   257  	}
   258  
   259  	return
   260  }
   261  
   262  // GetPreparer prepares the Get request.
   263  func (client PrivateLinkScopesClient) GetPreparer(ctx context.Context, resourceGroupName string, scopeName string) (*http.Request, error) {
   264  	pathParameters := map[string]interface{}{
   265  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   266  		"scopeName":         autorest.Encode("path", scopeName),
   267  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   268  	}
   269  
   270  	const APIVersion = "2021-07-01-preview"
   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/privateLinkScopes/{scopeName}", pathParameters),
   279  		autorest.WithQueryParameters(queryParameters))
   280  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   281  }
   282  
   283  // GetSender sends the Get request. The method will close the
   284  // http.Response Body if it receives an error.
   285  func (client PrivateLinkScopesClient) GetSender(req *http.Request) (*http.Response, error) {
   286  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   287  }
   288  
   289  // GetResponder handles the response to the Get request. The method always
   290  // closes the http.Response Body.
   291  func (client PrivateLinkScopesClient) GetResponder(resp *http.Response) (result AzureMonitorPrivateLinkScope, 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  // List gets a list of all Azure Monitor PrivateLinkScopes within a subscription.
   302  func (client PrivateLinkScopesClient) List(ctx context.Context) (result AzureMonitorPrivateLinkScopeListResultPage, err error) {
   303  	if tracing.IsEnabled() {
   304  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopesClient.List")
   305  		defer func() {
   306  			sc := -1
   307  			if result.amplslr.Response.Response != nil {
   308  				sc = result.amplslr.Response.Response.StatusCode
   309  			}
   310  			tracing.EndSpan(ctx, sc, err)
   311  		}()
   312  	}
   313  	if err := validation.Validate([]validation.Validation{
   314  		{TargetValue: client.SubscriptionID,
   315  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   316  		return result, validation.NewError("diagnostics.PrivateLinkScopesClient", "List", err.Error())
   317  	}
   318  
   319  	result.fn = client.listNextResults
   320  	req, err := client.ListPreparer(ctx)
   321  	if err != nil {
   322  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "List", nil, "Failure preparing request")
   323  		return
   324  	}
   325  
   326  	resp, err := client.ListSender(req)
   327  	if err != nil {
   328  		result.amplslr.Response = autorest.Response{Response: resp}
   329  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "List", resp, "Failure sending request")
   330  		return
   331  	}
   332  
   333  	result.amplslr, err = client.ListResponder(resp)
   334  	if err != nil {
   335  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "List", resp, "Failure responding to request")
   336  		return
   337  	}
   338  	if result.amplslr.hasNextLink() && result.amplslr.IsEmpty() {
   339  		err = result.NextWithContext(ctx)
   340  		return
   341  	}
   342  
   343  	return
   344  }
   345  
   346  // ListPreparer prepares the List request.
   347  func (client PrivateLinkScopesClient) ListPreparer(ctx context.Context) (*http.Request, error) {
   348  	pathParameters := map[string]interface{}{
   349  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   350  	}
   351  
   352  	const APIVersion = "2021-07-01-preview"
   353  	queryParameters := map[string]interface{}{
   354  		"api-version": APIVersion,
   355  	}
   356  
   357  	preparer := autorest.CreatePreparer(
   358  		autorest.AsGet(),
   359  		autorest.WithBaseURL(client.BaseURI),
   360  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/privateLinkScopes", pathParameters),
   361  		autorest.WithQueryParameters(queryParameters))
   362  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   363  }
   364  
   365  // ListSender sends the List request. The method will close the
   366  // http.Response Body if it receives an error.
   367  func (client PrivateLinkScopesClient) ListSender(req *http.Request) (*http.Response, error) {
   368  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   369  }
   370  
   371  // ListResponder handles the response to the List request. The method always
   372  // closes the http.Response Body.
   373  func (client PrivateLinkScopesClient) ListResponder(resp *http.Response) (result AzureMonitorPrivateLinkScopeListResult, err error) {
   374  	err = autorest.Respond(
   375  		resp,
   376  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   377  		autorest.ByUnmarshallingJSON(&result),
   378  		autorest.ByClosing())
   379  	result.Response = autorest.Response{Response: resp}
   380  	return
   381  }
   382  
   383  // listNextResults retrieves the next set of results, if any.
   384  func (client PrivateLinkScopesClient) listNextResults(ctx context.Context, lastResults AzureMonitorPrivateLinkScopeListResult) (result AzureMonitorPrivateLinkScopeListResult, err error) {
   385  	req, err := lastResults.azureMonitorPrivateLinkScopeListResultPreparer(ctx)
   386  	if err != nil {
   387  		return result, autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "listNextResults", nil, "Failure preparing next results request")
   388  	}
   389  	if req == nil {
   390  		return
   391  	}
   392  	resp, err := client.ListSender(req)
   393  	if err != nil {
   394  		result.Response = autorest.Response{Response: resp}
   395  		return result, autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "listNextResults", resp, "Failure sending next results request")
   396  	}
   397  	result, err = client.ListResponder(resp)
   398  	if err != nil {
   399  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "listNextResults", resp, "Failure responding to next results request")
   400  	}
   401  	return
   402  }
   403  
   404  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   405  func (client PrivateLinkScopesClient) ListComplete(ctx context.Context) (result AzureMonitorPrivateLinkScopeListResultIterator, err error) {
   406  	if tracing.IsEnabled() {
   407  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopesClient.List")
   408  		defer func() {
   409  			sc := -1
   410  			if result.Response().Response.Response != nil {
   411  				sc = result.page.Response().Response.Response.StatusCode
   412  			}
   413  			tracing.EndSpan(ctx, sc, err)
   414  		}()
   415  	}
   416  	result.page, err = client.List(ctx)
   417  	return
   418  }
   419  
   420  // ListByResourceGroup gets a list of Azure Monitor PrivateLinkScopes within a resource group.
   421  // Parameters:
   422  // resourceGroupName - the name of the resource group. The name is case insensitive.
   423  func (client PrivateLinkScopesClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result AzureMonitorPrivateLinkScopeListResultPage, err error) {
   424  	if tracing.IsEnabled() {
   425  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopesClient.ListByResourceGroup")
   426  		defer func() {
   427  			sc := -1
   428  			if result.amplslr.Response.Response != nil {
   429  				sc = result.amplslr.Response.Response.StatusCode
   430  			}
   431  			tracing.EndSpan(ctx, sc, err)
   432  		}()
   433  	}
   434  	if err := validation.Validate([]validation.Validation{
   435  		{TargetValue: resourceGroupName,
   436  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   437  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   438  		{TargetValue: client.SubscriptionID,
   439  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   440  		return result, validation.NewError("diagnostics.PrivateLinkScopesClient", "ListByResourceGroup", err.Error())
   441  	}
   442  
   443  	result.fn = client.listByResourceGroupNextResults
   444  	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
   445  	if err != nil {
   446  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "ListByResourceGroup", nil, "Failure preparing request")
   447  		return
   448  	}
   449  
   450  	resp, err := client.ListByResourceGroupSender(req)
   451  	if err != nil {
   452  		result.amplslr.Response = autorest.Response{Response: resp}
   453  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "ListByResourceGroup", resp, "Failure sending request")
   454  		return
   455  	}
   456  
   457  	result.amplslr, err = client.ListByResourceGroupResponder(resp)
   458  	if err != nil {
   459  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "ListByResourceGroup", resp, "Failure responding to request")
   460  		return
   461  	}
   462  	if result.amplslr.hasNextLink() && result.amplslr.IsEmpty() {
   463  		err = result.NextWithContext(ctx)
   464  		return
   465  	}
   466  
   467  	return
   468  }
   469  
   470  // ListByResourceGroupPreparer prepares the ListByResourceGroup request.
   471  func (client PrivateLinkScopesClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
   472  	pathParameters := map[string]interface{}{
   473  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   474  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   475  	}
   476  
   477  	const APIVersion = "2021-07-01-preview"
   478  	queryParameters := map[string]interface{}{
   479  		"api-version": APIVersion,
   480  	}
   481  
   482  	preparer := autorest.CreatePreparer(
   483  		autorest.AsGet(),
   484  		autorest.WithBaseURL(client.BaseURI),
   485  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/privateLinkScopes", pathParameters),
   486  		autorest.WithQueryParameters(queryParameters))
   487  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   488  }
   489  
   490  // ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
   491  // http.Response Body if it receives an error.
   492  func (client PrivateLinkScopesClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
   493  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   494  }
   495  
   496  // ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
   497  // closes the http.Response Body.
   498  func (client PrivateLinkScopesClient) ListByResourceGroupResponder(resp *http.Response) (result AzureMonitorPrivateLinkScopeListResult, err error) {
   499  	err = autorest.Respond(
   500  		resp,
   501  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   502  		autorest.ByUnmarshallingJSON(&result),
   503  		autorest.ByClosing())
   504  	result.Response = autorest.Response{Response: resp}
   505  	return
   506  }
   507  
   508  // listByResourceGroupNextResults retrieves the next set of results, if any.
   509  func (client PrivateLinkScopesClient) listByResourceGroupNextResults(ctx context.Context, lastResults AzureMonitorPrivateLinkScopeListResult) (result AzureMonitorPrivateLinkScopeListResult, err error) {
   510  	req, err := lastResults.azureMonitorPrivateLinkScopeListResultPreparer(ctx)
   511  	if err != nil {
   512  		return result, autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
   513  	}
   514  	if req == nil {
   515  		return
   516  	}
   517  	resp, err := client.ListByResourceGroupSender(req)
   518  	if err != nil {
   519  		result.Response = autorest.Response{Response: resp}
   520  		return result, autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
   521  	}
   522  	result, err = client.ListByResourceGroupResponder(resp)
   523  	if err != nil {
   524  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
   525  	}
   526  	return
   527  }
   528  
   529  // ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
   530  func (client PrivateLinkScopesClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result AzureMonitorPrivateLinkScopeListResultIterator, err error) {
   531  	if tracing.IsEnabled() {
   532  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopesClient.ListByResourceGroup")
   533  		defer func() {
   534  			sc := -1
   535  			if result.Response().Response.Response != nil {
   536  				sc = result.page.Response().Response.Response.StatusCode
   537  			}
   538  			tracing.EndSpan(ctx, sc, err)
   539  		}()
   540  	}
   541  	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName)
   542  	return
   543  }
   544  
   545  // UpdateTags updates an existing PrivateLinkScope's tags. To update other fields use the CreateOrUpdate method.
   546  // Parameters:
   547  // resourceGroupName - the name of the resource group. The name is case insensitive.
   548  // scopeName - the name of the Azure Monitor PrivateLinkScope resource.
   549  // privateLinkScopeTags - updated tag information to set into the PrivateLinkScope instance.
   550  func (client PrivateLinkScopesClient) UpdateTags(ctx context.Context, resourceGroupName string, scopeName string, privateLinkScopeTags TagsResource) (result AzureMonitorPrivateLinkScope, err error) {
   551  	if tracing.IsEnabled() {
   552  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopesClient.UpdateTags")
   553  		defer func() {
   554  			sc := -1
   555  			if result.Response.Response != nil {
   556  				sc = result.Response.Response.StatusCode
   557  			}
   558  			tracing.EndSpan(ctx, sc, err)
   559  		}()
   560  	}
   561  	if err := validation.Validate([]validation.Validation{
   562  		{TargetValue: resourceGroupName,
   563  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   564  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   565  		{TargetValue: client.SubscriptionID,
   566  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   567  		return result, validation.NewError("diagnostics.PrivateLinkScopesClient", "UpdateTags", err.Error())
   568  	}
   569  
   570  	req, err := client.UpdateTagsPreparer(ctx, resourceGroupName, scopeName, privateLinkScopeTags)
   571  	if err != nil {
   572  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "UpdateTags", nil, "Failure preparing request")
   573  		return
   574  	}
   575  
   576  	resp, err := client.UpdateTagsSender(req)
   577  	if err != nil {
   578  		result.Response = autorest.Response{Response: resp}
   579  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "UpdateTags", resp, "Failure sending request")
   580  		return
   581  	}
   582  
   583  	result, err = client.UpdateTagsResponder(resp)
   584  	if err != nil {
   585  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopesClient", "UpdateTags", resp, "Failure responding to request")
   586  		return
   587  	}
   588  
   589  	return
   590  }
   591  
   592  // UpdateTagsPreparer prepares the UpdateTags request.
   593  func (client PrivateLinkScopesClient) UpdateTagsPreparer(ctx context.Context, resourceGroupName string, scopeName string, privateLinkScopeTags TagsResource) (*http.Request, error) {
   594  	pathParameters := map[string]interface{}{
   595  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   596  		"scopeName":         autorest.Encode("path", scopeName),
   597  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   598  	}
   599  
   600  	const APIVersion = "2021-07-01-preview"
   601  	queryParameters := map[string]interface{}{
   602  		"api-version": APIVersion,
   603  	}
   604  
   605  	preparer := autorest.CreatePreparer(
   606  		autorest.AsContentType("application/json; charset=utf-8"),
   607  		autorest.AsPatch(),
   608  		autorest.WithBaseURL(client.BaseURI),
   609  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/privateLinkScopes/{scopeName}", pathParameters),
   610  		autorest.WithJSON(privateLinkScopeTags),
   611  		autorest.WithQueryParameters(queryParameters))
   612  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   613  }
   614  
   615  // UpdateTagsSender sends the UpdateTags request. The method will close the
   616  // http.Response Body if it receives an error.
   617  func (client PrivateLinkScopesClient) UpdateTagsSender(req *http.Request) (*http.Response, error) {
   618  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   619  }
   620  
   621  // UpdateTagsResponder handles the response to the UpdateTags request. The method always
   622  // closes the http.Response Body.
   623  func (client PrivateLinkScopesClient) UpdateTagsResponder(resp *http.Response) (result AzureMonitorPrivateLinkScope, err error) {
   624  	err = autorest.Respond(
   625  		resp,
   626  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   627  		autorest.ByUnmarshallingJSON(&result),
   628  		autorest.ByClosing())
   629  	result.Response = autorest.Response{Response: resp}
   630  	return
   631  }
   632  

View as plain text