...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-05-01-preview/diagnostics/privateendpointconnections.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  // PrivateEndpointConnectionsClient is the monitor Management Client
    19  type PrivateEndpointConnectionsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewPrivateEndpointConnectionsClient creates an instance of the PrivateEndpointConnectionsClient client.
    24  func NewPrivateEndpointConnectionsClient(subscriptionID string) PrivateEndpointConnectionsClient {
    25  	return NewPrivateEndpointConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewPrivateEndpointConnectionsClientWithBaseURI creates an instance of the PrivateEndpointConnectionsClient 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 NewPrivateEndpointConnectionsClientWithBaseURI(baseURI string, subscriptionID string) PrivateEndpointConnectionsClient {
    32  	return PrivateEndpointConnectionsClient{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  // privateEndpointConnectionName - the name of the private endpoint connection.
    40  func (client PrivateEndpointConnectionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, scopeName string, privateEndpointConnectionName string, parameters PrivateEndpointConnection) (result PrivateEndpointConnectionsCreateOrUpdateFuture, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.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}}},
    57  		{TargetValue: parameters,
    58  			Constraints: []validation.Constraint{{Target: "parameters.PrivateEndpointConnectionProperties", Name: validation.Null, Rule: false,
    59  				Chain: []validation.Constraint{{Target: "parameters.PrivateEndpointConnectionProperties.PrivateLinkServiceConnectionState", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
    60  		return result, validation.NewError("diagnostics.PrivateEndpointConnectionsClient", "CreateOrUpdate", err.Error())
    61  	}
    62  
    63  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, scopeName, privateEndpointConnectionName, parameters)
    64  	if err != nil {
    65  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateEndpointConnectionsClient", "CreateOrUpdate", nil, "Failure preparing request")
    66  		return
    67  	}
    68  
    69  	result, err = client.CreateOrUpdateSender(req)
    70  	if err != nil {
    71  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateEndpointConnectionsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    72  		return
    73  	}
    74  
    75  	return
    76  }
    77  
    78  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    79  func (client PrivateEndpointConnectionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, scopeName string, privateEndpointConnectionName string, parameters PrivateEndpointConnection) (*http.Request, error) {
    80  	pathParameters := map[string]interface{}{
    81  		"privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
    82  		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
    83  		"scopeName":                     autorest.Encode("path", scopeName),
    84  		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
    85  	}
    86  
    87  	const APIVersion = "2021-07-01-preview"
    88  	queryParameters := map[string]interface{}{
    89  		"api-version": APIVersion,
    90  	}
    91  
    92  	preparer := autorest.CreatePreparer(
    93  		autorest.AsContentType("application/json; charset=utf-8"),
    94  		autorest.AsPut(),
    95  		autorest.WithBaseURL(client.BaseURI),
    96  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/privateLinkScopes/{scopeName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters),
    97  		autorest.WithJSON(parameters),
    98  		autorest.WithQueryParameters(queryParameters))
    99  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   100  }
   101  
   102  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   103  // http.Response Body if it receives an error.
   104  func (client PrivateEndpointConnectionsClient) CreateOrUpdateSender(req *http.Request) (future PrivateEndpointConnectionsCreateOrUpdateFuture, err error) {
   105  	var resp *http.Response
   106  	future.FutureAPI = &azure.Future{}
   107  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   108  	if err != nil {
   109  		return
   110  	}
   111  	var azf azure.Future
   112  	azf, err = azure.NewFutureFromResponse(resp)
   113  	future.FutureAPI = &azf
   114  	future.Result = future.result
   115  	return
   116  }
   117  
   118  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   119  // closes the http.Response Body.
   120  func (client PrivateEndpointConnectionsClient) CreateOrUpdateResponder(resp *http.Response) (result PrivateEndpointConnection, err error) {
   121  	err = autorest.Respond(
   122  		resp,
   123  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   124  		autorest.ByUnmarshallingJSON(&result),
   125  		autorest.ByClosing())
   126  	result.Response = autorest.Response{Response: resp}
   127  	return
   128  }
   129  
   130  // Delete deletes a private endpoint connection with a given name.
   131  // Parameters:
   132  // resourceGroupName - the name of the resource group. The name is case insensitive.
   133  // scopeName - the name of the Azure Monitor PrivateLinkScope resource.
   134  // privateEndpointConnectionName - the name of the private endpoint connection.
   135  func (client PrivateEndpointConnectionsClient) Delete(ctx context.Context, resourceGroupName string, scopeName string, privateEndpointConnectionName string) (result PrivateEndpointConnectionsDeleteFuture, err error) {
   136  	if tracing.IsEnabled() {
   137  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Delete")
   138  		defer func() {
   139  			sc := -1
   140  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   141  				sc = result.FutureAPI.Response().StatusCode
   142  			}
   143  			tracing.EndSpan(ctx, sc, err)
   144  		}()
   145  	}
   146  	if err := validation.Validate([]validation.Validation{
   147  		{TargetValue: client.SubscriptionID,
   148  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   149  		{TargetValue: resourceGroupName,
   150  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   151  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   152  		return result, validation.NewError("diagnostics.PrivateEndpointConnectionsClient", "Delete", err.Error())
   153  	}
   154  
   155  	req, err := client.DeletePreparer(ctx, resourceGroupName, scopeName, privateEndpointConnectionName)
   156  	if err != nil {
   157  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateEndpointConnectionsClient", "Delete", nil, "Failure preparing request")
   158  		return
   159  	}
   160  
   161  	result, err = client.DeleteSender(req)
   162  	if err != nil {
   163  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateEndpointConnectionsClient", "Delete", result.Response(), "Failure sending request")
   164  		return
   165  	}
   166  
   167  	return
   168  }
   169  
   170  // DeletePreparer prepares the Delete request.
   171  func (client PrivateEndpointConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, scopeName string, privateEndpointConnectionName string) (*http.Request, error) {
   172  	pathParameters := map[string]interface{}{
   173  		"privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
   174  		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
   175  		"scopeName":                     autorest.Encode("path", scopeName),
   176  		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
   177  	}
   178  
   179  	const APIVersion = "2021-07-01-preview"
   180  	queryParameters := map[string]interface{}{
   181  		"api-version": APIVersion,
   182  	}
   183  
   184  	preparer := autorest.CreatePreparer(
   185  		autorest.AsDelete(),
   186  		autorest.WithBaseURL(client.BaseURI),
   187  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/privateLinkScopes/{scopeName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters),
   188  		autorest.WithQueryParameters(queryParameters))
   189  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   190  }
   191  
   192  // DeleteSender sends the Delete request. The method will close the
   193  // http.Response Body if it receives an error.
   194  func (client PrivateEndpointConnectionsClient) DeleteSender(req *http.Request) (future PrivateEndpointConnectionsDeleteFuture, err error) {
   195  	var resp *http.Response
   196  	future.FutureAPI = &azure.Future{}
   197  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   198  	if err != nil {
   199  		return
   200  	}
   201  	var azf azure.Future
   202  	azf, err = azure.NewFutureFromResponse(resp)
   203  	future.FutureAPI = &azf
   204  	future.Result = future.result
   205  	return
   206  }
   207  
   208  // DeleteResponder handles the response to the Delete request. The method always
   209  // closes the http.Response Body.
   210  func (client PrivateEndpointConnectionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   211  	err = autorest.Respond(
   212  		resp,
   213  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   214  		autorest.ByClosing())
   215  	result.Response = resp
   216  	return
   217  }
   218  
   219  // Get gets a private endpoint connection.
   220  // Parameters:
   221  // resourceGroupName - the name of the resource group. The name is case insensitive.
   222  // scopeName - the name of the Azure Monitor PrivateLinkScope resource.
   223  // privateEndpointConnectionName - the name of the private endpoint connection.
   224  func (client PrivateEndpointConnectionsClient) Get(ctx context.Context, resourceGroupName string, scopeName string, privateEndpointConnectionName string) (result PrivateEndpointConnection, err error) {
   225  	if tracing.IsEnabled() {
   226  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Get")
   227  		defer func() {
   228  			sc := -1
   229  			if result.Response.Response != nil {
   230  				sc = result.Response.Response.StatusCode
   231  			}
   232  			tracing.EndSpan(ctx, sc, err)
   233  		}()
   234  	}
   235  	if err := validation.Validate([]validation.Validation{
   236  		{TargetValue: client.SubscriptionID,
   237  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   238  		{TargetValue: resourceGroupName,
   239  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   240  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   241  		return result, validation.NewError("diagnostics.PrivateEndpointConnectionsClient", "Get", err.Error())
   242  	}
   243  
   244  	req, err := client.GetPreparer(ctx, resourceGroupName, scopeName, privateEndpointConnectionName)
   245  	if err != nil {
   246  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateEndpointConnectionsClient", "Get", nil, "Failure preparing request")
   247  		return
   248  	}
   249  
   250  	resp, err := client.GetSender(req)
   251  	if err != nil {
   252  		result.Response = autorest.Response{Response: resp}
   253  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateEndpointConnectionsClient", "Get", resp, "Failure sending request")
   254  		return
   255  	}
   256  
   257  	result, err = client.GetResponder(resp)
   258  	if err != nil {
   259  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateEndpointConnectionsClient", "Get", resp, "Failure responding to request")
   260  		return
   261  	}
   262  
   263  	return
   264  }
   265  
   266  // GetPreparer prepares the Get request.
   267  func (client PrivateEndpointConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, scopeName string, privateEndpointConnectionName string) (*http.Request, error) {
   268  	pathParameters := map[string]interface{}{
   269  		"privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
   270  		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
   271  		"scopeName":                     autorest.Encode("path", scopeName),
   272  		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
   273  	}
   274  
   275  	const APIVersion = "2021-07-01-preview"
   276  	queryParameters := map[string]interface{}{
   277  		"api-version": APIVersion,
   278  	}
   279  
   280  	preparer := autorest.CreatePreparer(
   281  		autorest.AsGet(),
   282  		autorest.WithBaseURL(client.BaseURI),
   283  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/privateLinkScopes/{scopeName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters),
   284  		autorest.WithQueryParameters(queryParameters))
   285  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   286  }
   287  
   288  // GetSender sends the Get request. The method will close the
   289  // http.Response Body if it receives an error.
   290  func (client PrivateEndpointConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
   291  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   292  }
   293  
   294  // GetResponder handles the response to the Get request. The method always
   295  // closes the http.Response Body.
   296  func (client PrivateEndpointConnectionsClient) GetResponder(resp *http.Response) (result PrivateEndpointConnection, err error) {
   297  	err = autorest.Respond(
   298  		resp,
   299  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   300  		autorest.ByUnmarshallingJSON(&result),
   301  		autorest.ByClosing())
   302  	result.Response = autorest.Response{Response: resp}
   303  	return
   304  }
   305  
   306  // ListByPrivateLinkScope gets all private endpoint connections on a private link scope.
   307  // Parameters:
   308  // resourceGroupName - the name of the resource group. The name is case insensitive.
   309  // scopeName - the name of the Azure Monitor PrivateLinkScope resource.
   310  func (client PrivateEndpointConnectionsClient) ListByPrivateLinkScope(ctx context.Context, resourceGroupName string, scopeName string) (result PrivateEndpointConnectionListResult, err error) {
   311  	if tracing.IsEnabled() {
   312  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.ListByPrivateLinkScope")
   313  		defer func() {
   314  			sc := -1
   315  			if result.Response.Response != nil {
   316  				sc = result.Response.Response.StatusCode
   317  			}
   318  			tracing.EndSpan(ctx, sc, err)
   319  		}()
   320  	}
   321  	if err := validation.Validate([]validation.Validation{
   322  		{TargetValue: client.SubscriptionID,
   323  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   324  		{TargetValue: resourceGroupName,
   325  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   326  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   327  		return result, validation.NewError("diagnostics.PrivateEndpointConnectionsClient", "ListByPrivateLinkScope", err.Error())
   328  	}
   329  
   330  	req, err := client.ListByPrivateLinkScopePreparer(ctx, resourceGroupName, scopeName)
   331  	if err != nil {
   332  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateEndpointConnectionsClient", "ListByPrivateLinkScope", nil, "Failure preparing request")
   333  		return
   334  	}
   335  
   336  	resp, err := client.ListByPrivateLinkScopeSender(req)
   337  	if err != nil {
   338  		result.Response = autorest.Response{Response: resp}
   339  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateEndpointConnectionsClient", "ListByPrivateLinkScope", resp, "Failure sending request")
   340  		return
   341  	}
   342  
   343  	result, err = client.ListByPrivateLinkScopeResponder(resp)
   344  	if err != nil {
   345  		err = autorest.NewErrorWithError(err, "diagnostics.PrivateEndpointConnectionsClient", "ListByPrivateLinkScope", resp, "Failure responding to request")
   346  		return
   347  	}
   348  
   349  	return
   350  }
   351  
   352  // ListByPrivateLinkScopePreparer prepares the ListByPrivateLinkScope request.
   353  func (client PrivateEndpointConnectionsClient) ListByPrivateLinkScopePreparer(ctx context.Context, resourceGroupName string, scopeName string) (*http.Request, error) {
   354  	pathParameters := map[string]interface{}{
   355  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   356  		"scopeName":         autorest.Encode("path", scopeName),
   357  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   358  	}
   359  
   360  	const APIVersion = "2021-07-01-preview"
   361  	queryParameters := map[string]interface{}{
   362  		"api-version": APIVersion,
   363  	}
   364  
   365  	preparer := autorest.CreatePreparer(
   366  		autorest.AsGet(),
   367  		autorest.WithBaseURL(client.BaseURI),
   368  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/privateLinkScopes/{scopeName}/privateEndpointConnections", pathParameters),
   369  		autorest.WithQueryParameters(queryParameters))
   370  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   371  }
   372  
   373  // ListByPrivateLinkScopeSender sends the ListByPrivateLinkScope request. The method will close the
   374  // http.Response Body if it receives an error.
   375  func (client PrivateEndpointConnectionsClient) ListByPrivateLinkScopeSender(req *http.Request) (*http.Response, error) {
   376  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   377  }
   378  
   379  // ListByPrivateLinkScopeResponder handles the response to the ListByPrivateLinkScope request. The method always
   380  // closes the http.Response Body.
   381  func (client PrivateEndpointConnectionsClient) ListByPrivateLinkScopeResponder(resp *http.Response) (result PrivateEndpointConnectionListResult, err error) {
   382  	err = autorest.Respond(
   383  		resp,
   384  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   385  		autorest.ByUnmarshallingJSON(&result),
   386  		autorest.ByClosing())
   387  	result.Response = autorest.Response{Response: resp}
   388  	return
   389  }
   390  

View as plain text