...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-05-01-preview/diagnostics/privatelinkscopedresources.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  // PrivateLinkScopedResourcesClient is the monitor Management Client
    19  type PrivateLinkScopedResourcesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewPrivateLinkScopedResourcesClient creates an instance of the PrivateLinkScopedResourcesClient client.
    24  func NewPrivateLinkScopedResourcesClient(subscriptionID string) PrivateLinkScopedResourcesClient {
    25  	return NewPrivateLinkScopedResourcesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewPrivateLinkScopedResourcesClientWithBaseURI creates an instance of the PrivateLinkScopedResourcesClient client
    29  // using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
    30  // clouds, Azure stack).
    31  func NewPrivateLinkScopedResourcesClientWithBaseURI(baseURI string, subscriptionID string) PrivateLinkScopedResourcesClient {
    32  	return PrivateLinkScopedResourcesClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // CreateOrUpdate approve or reject a private endpoint connection with a given name.
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group. The name is case insensitive.
    38  // scopeName - the name of the Azure Monitor PrivateLinkScope resource.
    39  // name - the name of the scoped resource object.
    40  func (client PrivateLinkScopedResourcesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, scopeName string, name string, parameters ScopedResource) (result PrivateLinkScopedResourcesCreateOrUpdateFuture, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopedResourcesClient.CreateOrUpdate")
    43  		defer func() {
    44  			sc := -1
    45  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    46  				sc = result.FutureAPI.Response().StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	if err := validation.Validate([]validation.Validation{
    52  		{TargetValue: client.SubscriptionID,
    53  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    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}}}}); err != nil {
    57  		return result, validation.NewError("diagnostics.PrivateLinkScopedResourcesClient", "CreateOrUpdate", err.Error())
    58  	}
    59  
    60  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, scopeName, name, parameters)
    61  	if err != nil {
    62  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopedResourcesClient", "CreateOrUpdate", nil, "Failure preparing request")
    63  		return
    64  	}
    65  
    66  	result, err = client.CreateOrUpdateSender(req)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopedResourcesClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    69  		return
    70  	}
    71  
    72  	return
    73  }
    74  
    75  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    76  func (client PrivateLinkScopedResourcesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, scopeName string, name string, parameters ScopedResource) (*http.Request, error) {
    77  	pathParameters := map[string]interface{}{
    78  		"name":              autorest.Encode("path", name),
    79  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    80  		"scopeName":         autorest.Encode("path", scopeName),
    81  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    82  	}
    83  
    84  	const APIVersion = "2021-07-01-preview"
    85  	queryParameters := map[string]interface{}{
    86  		"api-version": APIVersion,
    87  	}
    88  
    89  	parameters.SystemData = nil
    90  	preparer := autorest.CreatePreparer(
    91  		autorest.AsContentType("application/json; charset=utf-8"),
    92  		autorest.AsPut(),
    93  		autorest.WithBaseURL(client.BaseURI),
    94  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/privateLinkScopes/{scopeName}/scopedResources/{name}", pathParameters),
    95  		autorest.WithJSON(parameters),
    96  		autorest.WithQueryParameters(queryParameters))
    97  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    98  }
    99  
   100  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   101  // http.Response Body if it receives an error.
   102  func (client PrivateLinkScopedResourcesClient) CreateOrUpdateSender(req *http.Request) (future PrivateLinkScopedResourcesCreateOrUpdateFuture, err error) {
   103  	var resp *http.Response
   104  	future.FutureAPI = &azure.Future{}
   105  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   106  	if err != nil {
   107  		return
   108  	}
   109  	var azf azure.Future
   110  	azf, err = azure.NewFutureFromResponse(resp)
   111  	future.FutureAPI = &azf
   112  	future.Result = future.result
   113  	return
   114  }
   115  
   116  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   117  // closes the http.Response Body.
   118  func (client PrivateLinkScopedResourcesClient) CreateOrUpdateResponder(resp *http.Response) (result ScopedResource, err error) {
   119  	err = autorest.Respond(
   120  		resp,
   121  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
   122  		autorest.ByUnmarshallingJSON(&result),
   123  		autorest.ByClosing())
   124  	result.Response = autorest.Response{Response: resp}
   125  	return
   126  }
   127  
   128  // Delete deletes a private endpoint connection with a given name.
   129  // Parameters:
   130  // resourceGroupName - the name of the resource group. The name is case insensitive.
   131  // scopeName - the name of the Azure Monitor PrivateLinkScope resource.
   132  // name - the name of the scoped resource object.
   133  func (client PrivateLinkScopedResourcesClient) Delete(ctx context.Context, resourceGroupName string, scopeName string, name string) (result PrivateLinkScopedResourcesDeleteFuture, err error) {
   134  	if tracing.IsEnabled() {
   135  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopedResourcesClient.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: client.SubscriptionID,
   146  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   147  		{TargetValue: resourceGroupName,
   148  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   149  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   150  		return result, validation.NewError("diagnostics.PrivateLinkScopedResourcesClient", "Delete", err.Error())
   151  	}
   152  
   153  	req, err := client.DeletePreparer(ctx, resourceGroupName, scopeName, name)
   154  	if err != nil {
   155  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopedResourcesClient", "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.PrivateLinkScopedResourcesClient", "Delete", result.Response(), "Failure sending request")
   162  		return
   163  	}
   164  
   165  	return
   166  }
   167  
   168  // DeletePreparer prepares the Delete request.
   169  func (client PrivateLinkScopedResourcesClient) DeletePreparer(ctx context.Context, resourceGroupName string, scopeName string, name string) (*http.Request, error) {
   170  	pathParameters := map[string]interface{}{
   171  		"name":              autorest.Encode("path", name),
   172  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   173  		"scopeName":         autorest.Encode("path", scopeName),
   174  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   175  	}
   176  
   177  	const APIVersion = "2021-07-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("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/privateLinkScopes/{scopeName}/scopedResources/{name}", 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 PrivateLinkScopedResourcesClient) DeleteSender(req *http.Request) (future PrivateLinkScopedResourcesDeleteFuture, err error) {
   193  	var resp *http.Response
   194  	future.FutureAPI = &azure.Future{}
   195  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   196  	if err != nil {
   197  		return
   198  	}
   199  	var azf azure.Future
   200  	azf, err = azure.NewFutureFromResponse(resp)
   201  	future.FutureAPI = &azf
   202  	future.Result = future.result
   203  	return
   204  }
   205  
   206  // DeleteResponder handles the response to the Delete request. The method always
   207  // closes the http.Response Body.
   208  func (client PrivateLinkScopedResourcesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   209  	err = autorest.Respond(
   210  		resp,
   211  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   212  		autorest.ByClosing())
   213  	result.Response = resp
   214  	return
   215  }
   216  
   217  // Get gets a scoped resource in a private link scope.
   218  // Parameters:
   219  // resourceGroupName - the name of the resource group. The name is case insensitive.
   220  // scopeName - the name of the Azure Monitor PrivateLinkScope resource.
   221  // name - the name of the scoped resource object.
   222  func (client PrivateLinkScopedResourcesClient) Get(ctx context.Context, resourceGroupName string, scopeName string, name string) (result ScopedResource, err error) {
   223  	if tracing.IsEnabled() {
   224  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopedResourcesClient.Get")
   225  		defer func() {
   226  			sc := -1
   227  			if result.Response.Response != nil {
   228  				sc = result.Response.Response.StatusCode
   229  			}
   230  			tracing.EndSpan(ctx, sc, err)
   231  		}()
   232  	}
   233  	if err := validation.Validate([]validation.Validation{
   234  		{TargetValue: client.SubscriptionID,
   235  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   236  		{TargetValue: resourceGroupName,
   237  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   238  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   239  		return result, validation.NewError("diagnostics.PrivateLinkScopedResourcesClient", "Get", err.Error())
   240  	}
   241  
   242  	req, err := client.GetPreparer(ctx, resourceGroupName, scopeName, name)
   243  	if err != nil {
   244  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopedResourcesClient", "Get", nil, "Failure preparing request")
   245  		return
   246  	}
   247  
   248  	resp, err := client.GetSender(req)
   249  	if err != nil {
   250  		result.Response = autorest.Response{Response: resp}
   251  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopedResourcesClient", "Get", resp, "Failure sending request")
   252  		return
   253  	}
   254  
   255  	result, err = client.GetResponder(resp)
   256  	if err != nil {
   257  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopedResourcesClient", "Get", resp, "Failure responding to request")
   258  		return
   259  	}
   260  
   261  	return
   262  }
   263  
   264  // GetPreparer prepares the Get request.
   265  func (client PrivateLinkScopedResourcesClient) GetPreparer(ctx context.Context, resourceGroupName string, scopeName string, name string) (*http.Request, error) {
   266  	pathParameters := map[string]interface{}{
   267  		"name":              autorest.Encode("path", name),
   268  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   269  		"scopeName":         autorest.Encode("path", scopeName),
   270  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   271  	}
   272  
   273  	const APIVersion = "2021-07-01-preview"
   274  	queryParameters := map[string]interface{}{
   275  		"api-version": APIVersion,
   276  	}
   277  
   278  	preparer := autorest.CreatePreparer(
   279  		autorest.AsGet(),
   280  		autorest.WithBaseURL(client.BaseURI),
   281  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/privateLinkScopes/{scopeName}/scopedResources/{name}", pathParameters),
   282  		autorest.WithQueryParameters(queryParameters))
   283  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   284  }
   285  
   286  // GetSender sends the Get request. The method will close the
   287  // http.Response Body if it receives an error.
   288  func (client PrivateLinkScopedResourcesClient) GetSender(req *http.Request) (*http.Response, error) {
   289  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   290  }
   291  
   292  // GetResponder handles the response to the Get request. The method always
   293  // closes the http.Response Body.
   294  func (client PrivateLinkScopedResourcesClient) GetResponder(resp *http.Response) (result ScopedResource, err error) {
   295  	err = autorest.Respond(
   296  		resp,
   297  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   298  		autorest.ByUnmarshallingJSON(&result),
   299  		autorest.ByClosing())
   300  	result.Response = autorest.Response{Response: resp}
   301  	return
   302  }
   303  
   304  // ListByPrivateLinkScope gets all private endpoint connections on a private link scope.
   305  // Parameters:
   306  // resourceGroupName - the name of the resource group. The name is case insensitive.
   307  // scopeName - the name of the Azure Monitor PrivateLinkScope resource.
   308  func (client PrivateLinkScopedResourcesClient) ListByPrivateLinkScope(ctx context.Context, resourceGroupName string, scopeName string) (result ScopedResourceListResultPage, err error) {
   309  	if tracing.IsEnabled() {
   310  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopedResourcesClient.ListByPrivateLinkScope")
   311  		defer func() {
   312  			sc := -1
   313  			if result.srlr.Response.Response != nil {
   314  				sc = result.srlr.Response.Response.StatusCode
   315  			}
   316  			tracing.EndSpan(ctx, sc, err)
   317  		}()
   318  	}
   319  	if err := validation.Validate([]validation.Validation{
   320  		{TargetValue: client.SubscriptionID,
   321  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   322  		{TargetValue: resourceGroupName,
   323  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   324  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   325  		return result, validation.NewError("diagnostics.PrivateLinkScopedResourcesClient", "ListByPrivateLinkScope", err.Error())
   326  	}
   327  
   328  	result.fn = client.listByPrivateLinkScopeNextResults
   329  	req, err := client.ListByPrivateLinkScopePreparer(ctx, resourceGroupName, scopeName)
   330  	if err != nil {
   331  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopedResourcesClient", "ListByPrivateLinkScope", nil, "Failure preparing request")
   332  		return
   333  	}
   334  
   335  	resp, err := client.ListByPrivateLinkScopeSender(req)
   336  	if err != nil {
   337  		result.srlr.Response = autorest.Response{Response: resp}
   338  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopedResourcesClient", "ListByPrivateLinkScope", resp, "Failure sending request")
   339  		return
   340  	}
   341  
   342  	result.srlr, err = client.ListByPrivateLinkScopeResponder(resp)
   343  	if err != nil {
   344  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopedResourcesClient", "ListByPrivateLinkScope", resp, "Failure responding to request")
   345  		return
   346  	}
   347  	if result.srlr.hasNextLink() && result.srlr.IsEmpty() {
   348  		err = result.NextWithContext(ctx)
   349  		return
   350  	}
   351  
   352  	return
   353  }
   354  
   355  // ListByPrivateLinkScopePreparer prepares the ListByPrivateLinkScope request.
   356  func (client PrivateLinkScopedResourcesClient) ListByPrivateLinkScopePreparer(ctx context.Context, resourceGroupName string, scopeName string) (*http.Request, error) {
   357  	pathParameters := map[string]interface{}{
   358  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   359  		"scopeName":         autorest.Encode("path", scopeName),
   360  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   361  	}
   362  
   363  	const APIVersion = "2021-07-01-preview"
   364  	queryParameters := map[string]interface{}{
   365  		"api-version": APIVersion,
   366  	}
   367  
   368  	preparer := autorest.CreatePreparer(
   369  		autorest.AsGet(),
   370  		autorest.WithBaseURL(client.BaseURI),
   371  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/privateLinkScopes/{scopeName}/scopedResources", pathParameters),
   372  		autorest.WithQueryParameters(queryParameters))
   373  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   374  }
   375  
   376  // ListByPrivateLinkScopeSender sends the ListByPrivateLinkScope request. The method will close the
   377  // http.Response Body if it receives an error.
   378  func (client PrivateLinkScopedResourcesClient) ListByPrivateLinkScopeSender(req *http.Request) (*http.Response, error) {
   379  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   380  }
   381  
   382  // ListByPrivateLinkScopeResponder handles the response to the ListByPrivateLinkScope request. The method always
   383  // closes the http.Response Body.
   384  func (client PrivateLinkScopedResourcesClient) ListByPrivateLinkScopeResponder(resp *http.Response) (result ScopedResourceListResult, err error) {
   385  	err = autorest.Respond(
   386  		resp,
   387  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   388  		autorest.ByUnmarshallingJSON(&result),
   389  		autorest.ByClosing())
   390  	result.Response = autorest.Response{Response: resp}
   391  	return
   392  }
   393  
   394  // listByPrivateLinkScopeNextResults retrieves the next set of results, if any.
   395  func (client PrivateLinkScopedResourcesClient) listByPrivateLinkScopeNextResults(ctx context.Context, lastResults ScopedResourceListResult) (result ScopedResourceListResult, err error) {
   396  	req, err := lastResults.scopedResourceListResultPreparer(ctx)
   397  	if err != nil {
   398  		return result, autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopedResourcesClient", "listByPrivateLinkScopeNextResults", nil, "Failure preparing next results request")
   399  	}
   400  	if req == nil {
   401  		return
   402  	}
   403  	resp, err := client.ListByPrivateLinkScopeSender(req)
   404  	if err != nil {
   405  		result.Response = autorest.Response{Response: resp}
   406  		return result, autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopedResourcesClient", "listByPrivateLinkScopeNextResults", resp, "Failure sending next results request")
   407  	}
   408  	result, err = client.ListByPrivateLinkScopeResponder(resp)
   409  	if err != nil {
   410  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateLinkScopedResourcesClient", "listByPrivateLinkScopeNextResults", resp, "Failure responding to next results request")
   411  	}
   412  	return
   413  }
   414  
   415  // ListByPrivateLinkScopeComplete enumerates all values, automatically crossing page boundaries as required.
   416  func (client PrivateLinkScopedResourcesClient) ListByPrivateLinkScopeComplete(ctx context.Context, resourceGroupName string, scopeName string) (result ScopedResourceListResultIterator, err error) {
   417  	if tracing.IsEnabled() {
   418  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkScopedResourcesClient.ListByPrivateLinkScope")
   419  		defer func() {
   420  			sc := -1
   421  			if result.Response().Response.Response != nil {
   422  				sc = result.page.Response().Response.Response.StatusCode
   423  			}
   424  			tracing.EndSpan(ctx, sc, err)
   425  		}()
   426  	}
   427  	result.page, err = client.ListByPrivateLinkScope(ctx, resourceGroupName, scopeName)
   428  	return
   429  }
   430  

View as plain text