...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2021-03-03-preview/devices/privateendpointconnections.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2021-03-03-preview/devices

     1  package devices
     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 use this API to manage the IoT hubs in your Azure subscription.
    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  // Delete delete private endpoint connection with the specified name
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group that contains the IoT hub.
    38  // resourceName - the name of the IoT hub.
    39  // privateEndpointConnectionName - the name of the private endpoint connection
    40  func (client PrivateEndpointConnectionsClient) Delete(ctx context.Context, resourceGroupName string, resourceName string, privateEndpointConnectionName string) (result PrivateEndpointConnectionsDeleteFuture, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Delete")
    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  	req, err := client.DeletePreparer(ctx, resourceGroupName, resourceName, privateEndpointConnectionName)
    52  	if err != nil {
    53  		err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "Delete", nil, "Failure preparing request")
    54  		return
    55  	}
    56  
    57  	result, err = client.DeleteSender(req)
    58  	if err != nil {
    59  		err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "Delete", result.Response(), "Failure sending request")
    60  		return
    61  	}
    62  
    63  	return
    64  }
    65  
    66  // DeletePreparer prepares the Delete request.
    67  func (client PrivateEndpointConnectionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, resourceName string, privateEndpointConnectionName string) (*http.Request, error) {
    68  	pathParameters := map[string]interface{}{
    69  		"privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
    70  		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
    71  		"resourceName":                  autorest.Encode("path", resourceName),
    72  		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
    73  	}
    74  
    75  	const APIVersion = "2021-03-03-preview"
    76  	queryParameters := map[string]interface{}{
    77  		"api-version": APIVersion,
    78  	}
    79  
    80  	preparer := autorest.CreatePreparer(
    81  		autorest.AsDelete(),
    82  		autorest.WithBaseURL(client.BaseURI),
    83  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/iotHubs/{resourceName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters),
    84  		autorest.WithQueryParameters(queryParameters))
    85  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    86  }
    87  
    88  // DeleteSender sends the Delete request. The method will close the
    89  // http.Response Body if it receives an error.
    90  func (client PrivateEndpointConnectionsClient) DeleteSender(req *http.Request) (future PrivateEndpointConnectionsDeleteFuture, err error) {
    91  	var resp *http.Response
    92  	future.FutureAPI = &azure.Future{}
    93  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
    94  	if err != nil {
    95  		return
    96  	}
    97  	var azf azure.Future
    98  	azf, err = azure.NewFutureFromResponse(resp)
    99  	future.FutureAPI = &azf
   100  	future.Result = future.result
   101  	return
   102  }
   103  
   104  // DeleteResponder handles the response to the Delete request. The method always
   105  // closes the http.Response Body.
   106  func (client PrivateEndpointConnectionsClient) DeleteResponder(resp *http.Response) (result PrivateEndpointConnection, err error) {
   107  	err = autorest.Respond(
   108  		resp,
   109  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   110  		autorest.ByUnmarshallingJSON(&result),
   111  		autorest.ByClosing())
   112  	result.Response = autorest.Response{Response: resp}
   113  	return
   114  }
   115  
   116  // Get get private endpoint connection properties
   117  // Parameters:
   118  // resourceGroupName - the name of the resource group that contains the IoT hub.
   119  // resourceName - the name of the IoT hub.
   120  // privateEndpointConnectionName - the name of the private endpoint connection
   121  func (client PrivateEndpointConnectionsClient) Get(ctx context.Context, resourceGroupName string, resourceName string, privateEndpointConnectionName string) (result PrivateEndpointConnection, err error) {
   122  	if tracing.IsEnabled() {
   123  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Get")
   124  		defer func() {
   125  			sc := -1
   126  			if result.Response.Response != nil {
   127  				sc = result.Response.Response.StatusCode
   128  			}
   129  			tracing.EndSpan(ctx, sc, err)
   130  		}()
   131  	}
   132  	req, err := client.GetPreparer(ctx, resourceGroupName, resourceName, privateEndpointConnectionName)
   133  	if err != nil {
   134  		err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "Get", nil, "Failure preparing request")
   135  		return
   136  	}
   137  
   138  	resp, err := client.GetSender(req)
   139  	if err != nil {
   140  		result.Response = autorest.Response{Response: resp}
   141  		err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "Get", resp, "Failure sending request")
   142  		return
   143  	}
   144  
   145  	result, err = client.GetResponder(resp)
   146  	if err != nil {
   147  		err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "Get", resp, "Failure responding to request")
   148  		return
   149  	}
   150  
   151  	return
   152  }
   153  
   154  // GetPreparer prepares the Get request.
   155  func (client PrivateEndpointConnectionsClient) GetPreparer(ctx context.Context, resourceGroupName string, resourceName string, privateEndpointConnectionName string) (*http.Request, error) {
   156  	pathParameters := map[string]interface{}{
   157  		"privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
   158  		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
   159  		"resourceName":                  autorest.Encode("path", resourceName),
   160  		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
   161  	}
   162  
   163  	const APIVersion = "2021-03-03-preview"
   164  	queryParameters := map[string]interface{}{
   165  		"api-version": APIVersion,
   166  	}
   167  
   168  	preparer := autorest.CreatePreparer(
   169  		autorest.AsGet(),
   170  		autorest.WithBaseURL(client.BaseURI),
   171  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/iotHubs/{resourceName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters),
   172  		autorest.WithQueryParameters(queryParameters))
   173  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   174  }
   175  
   176  // GetSender sends the Get request. The method will close the
   177  // http.Response Body if it receives an error.
   178  func (client PrivateEndpointConnectionsClient) GetSender(req *http.Request) (*http.Response, error) {
   179  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   180  }
   181  
   182  // GetResponder handles the response to the Get request. The method always
   183  // closes the http.Response Body.
   184  func (client PrivateEndpointConnectionsClient) GetResponder(resp *http.Response) (result PrivateEndpointConnection, err error) {
   185  	err = autorest.Respond(
   186  		resp,
   187  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   188  		autorest.ByUnmarshallingJSON(&result),
   189  		autorest.ByClosing())
   190  	result.Response = autorest.Response{Response: resp}
   191  	return
   192  }
   193  
   194  // List list private endpoint connection properties
   195  // Parameters:
   196  // resourceGroupName - the name of the resource group that contains the IoT hub.
   197  // resourceName - the name of the IoT hub.
   198  func (client PrivateEndpointConnectionsClient) List(ctx context.Context, resourceGroupName string, resourceName string) (result ListPrivateEndpointConnection, err error) {
   199  	if tracing.IsEnabled() {
   200  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.List")
   201  		defer func() {
   202  			sc := -1
   203  			if result.Response.Response != nil {
   204  				sc = result.Response.Response.StatusCode
   205  			}
   206  			tracing.EndSpan(ctx, sc, err)
   207  		}()
   208  	}
   209  	req, err := client.ListPreparer(ctx, resourceGroupName, resourceName)
   210  	if err != nil {
   211  		err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "List", nil, "Failure preparing request")
   212  		return
   213  	}
   214  
   215  	resp, err := client.ListSender(req)
   216  	if err != nil {
   217  		result.Response = autorest.Response{Response: resp}
   218  		err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "List", resp, "Failure sending request")
   219  		return
   220  	}
   221  
   222  	result, err = client.ListResponder(resp)
   223  	if err != nil {
   224  		err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "List", resp, "Failure responding to request")
   225  		return
   226  	}
   227  
   228  	return
   229  }
   230  
   231  // ListPreparer prepares the List request.
   232  func (client PrivateEndpointConnectionsClient) ListPreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
   233  	pathParameters := map[string]interface{}{
   234  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   235  		"resourceName":      autorest.Encode("path", resourceName),
   236  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   237  	}
   238  
   239  	const APIVersion = "2021-03-03-preview"
   240  	queryParameters := map[string]interface{}{
   241  		"api-version": APIVersion,
   242  	}
   243  
   244  	preparer := autorest.CreatePreparer(
   245  		autorest.AsGet(),
   246  		autorest.WithBaseURL(client.BaseURI),
   247  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/iotHubs/{resourceName}/privateEndpointConnections", pathParameters),
   248  		autorest.WithQueryParameters(queryParameters))
   249  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   250  }
   251  
   252  // ListSender sends the List request. The method will close the
   253  // http.Response Body if it receives an error.
   254  func (client PrivateEndpointConnectionsClient) ListSender(req *http.Request) (*http.Response, error) {
   255  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   256  }
   257  
   258  // ListResponder handles the response to the List request. The method always
   259  // closes the http.Response Body.
   260  func (client PrivateEndpointConnectionsClient) ListResponder(resp *http.Response) (result ListPrivateEndpointConnection, err error) {
   261  	err = autorest.Respond(
   262  		resp,
   263  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   264  		autorest.ByUnmarshallingJSON(&result.Value),
   265  		autorest.ByClosing())
   266  	result.Response = autorest.Response{Response: resp}
   267  	return
   268  }
   269  
   270  // Update update the status of a private endpoint connection with the specified name
   271  // Parameters:
   272  // resourceGroupName - the name of the resource group that contains the IoT hub.
   273  // resourceName - the name of the IoT hub.
   274  // privateEndpointConnectionName - the name of the private endpoint connection
   275  // privateEndpointConnection - the private endpoint connection with updated properties
   276  func (client PrivateEndpointConnectionsClient) Update(ctx context.Context, resourceGroupName string, resourceName string, privateEndpointConnectionName string, privateEndpointConnection PrivateEndpointConnection) (result PrivateEndpointConnectionsUpdateFuture, err error) {
   277  	if tracing.IsEnabled() {
   278  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateEndpointConnectionsClient.Update")
   279  		defer func() {
   280  			sc := -1
   281  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   282  				sc = result.FutureAPI.Response().StatusCode
   283  			}
   284  			tracing.EndSpan(ctx, sc, err)
   285  		}()
   286  	}
   287  	if err := validation.Validate([]validation.Validation{
   288  		{TargetValue: privateEndpointConnection,
   289  			Constraints: []validation.Constraint{{Target: "privateEndpointConnection.Properties", Name: validation.Null, Rule: true,
   290  				Chain: []validation.Constraint{{Target: "privateEndpointConnection.Properties.PrivateLinkServiceConnectionState", Name: validation.Null, Rule: true,
   291  					Chain: []validation.Constraint{{Target: "privateEndpointConnection.Properties.PrivateLinkServiceConnectionState.Description", Name: validation.Null, Rule: true, Chain: nil}}},
   292  				}}}}}); err != nil {
   293  		return result, validation.NewError("devices.PrivateEndpointConnectionsClient", "Update", err.Error())
   294  	}
   295  
   296  	req, err := client.UpdatePreparer(ctx, resourceGroupName, resourceName, privateEndpointConnectionName, privateEndpointConnection)
   297  	if err != nil {
   298  		err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "Update", nil, "Failure preparing request")
   299  		return
   300  	}
   301  
   302  	result, err = client.UpdateSender(req)
   303  	if err != nil {
   304  		err = autorest.NewErrorWithError(err, "devices.PrivateEndpointConnectionsClient", "Update", result.Response(), "Failure sending request")
   305  		return
   306  	}
   307  
   308  	return
   309  }
   310  
   311  // UpdatePreparer prepares the Update request.
   312  func (client PrivateEndpointConnectionsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, privateEndpointConnectionName string, privateEndpointConnection PrivateEndpointConnection) (*http.Request, error) {
   313  	pathParameters := map[string]interface{}{
   314  		"privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
   315  		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
   316  		"resourceName":                  autorest.Encode("path", resourceName),
   317  		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
   318  	}
   319  
   320  	const APIVersion = "2021-03-03-preview"
   321  	queryParameters := map[string]interface{}{
   322  		"api-version": APIVersion,
   323  	}
   324  
   325  	privateEndpointConnection.ID = nil
   326  	privateEndpointConnection.Name = nil
   327  	privateEndpointConnection.Type = nil
   328  	preparer := autorest.CreatePreparer(
   329  		autorest.AsContentType("application/json; charset=utf-8"),
   330  		autorest.AsPut(),
   331  		autorest.WithBaseURL(client.BaseURI),
   332  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/iotHubs/{resourceName}/privateEndpointConnections/{privateEndpointConnectionName}", pathParameters),
   333  		autorest.WithJSON(privateEndpointConnection),
   334  		autorest.WithQueryParameters(queryParameters))
   335  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   336  }
   337  
   338  // UpdateSender sends the Update request. The method will close the
   339  // http.Response Body if it receives an error.
   340  func (client PrivateEndpointConnectionsClient) UpdateSender(req *http.Request) (future PrivateEndpointConnectionsUpdateFuture, err error) {
   341  	var resp *http.Response
   342  	future.FutureAPI = &azure.Future{}
   343  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   344  	if err != nil {
   345  		return
   346  	}
   347  	var azf azure.Future
   348  	azf, err = azure.NewFutureFromResponse(resp)
   349  	future.FutureAPI = &azf
   350  	future.Result = future.result
   351  	return
   352  }
   353  
   354  // UpdateResponder handles the response to the Update request. The method always
   355  // closes the http.Response Body.
   356  func (client PrivateEndpointConnectionsClient) UpdateResponder(resp *http.Response) (result PrivateEndpointConnection, err error) {
   357  	err = autorest.Respond(
   358  		resp,
   359  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   360  		autorest.ByUnmarshallingJSON(&result),
   361  		autorest.ByClosing())
   362  	result.Response = autorest.Response{Response: resp}
   363  	return
   364  }
   365  

View as plain text