github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/applicationgatewayprivateendpointconnections_client.go (about)

     1  //go:build go1.18
     2  // +build go1.18
     3  
     4  // Copyright (c) Microsoft Corporation. All rights reserved.
     5  // Licensed under the MIT License. See License.txt in the project root for license information.
     6  // Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     8  
     9  package armnetwork
    10  
    11  import (
    12  	"context"
    13  	"errors"
    14  	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
    15  	"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
    16  	"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
    17  	"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
    18  	"net/http"
    19  	"net/url"
    20  	"strings"
    21  )
    22  
    23  // ApplicationGatewayPrivateEndpointConnectionsClient contains the methods for the ApplicationGatewayPrivateEndpointConnections group.
    24  // Don't use this type directly, use NewApplicationGatewayPrivateEndpointConnectionsClient() instead.
    25  type ApplicationGatewayPrivateEndpointConnectionsClient struct {
    26  	internal       *arm.Client
    27  	subscriptionID string
    28  }
    29  
    30  // NewApplicationGatewayPrivateEndpointConnectionsClient creates a new instance of ApplicationGatewayPrivateEndpointConnectionsClient with the specified values.
    31  //   - subscriptionID - The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription
    32  //     ID forms part of the URI for every service call.
    33  //   - credential - used to authorize requests. Usually a credential from azidentity.
    34  //   - options - pass nil to accept the default values.
    35  func NewApplicationGatewayPrivateEndpointConnectionsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ApplicationGatewayPrivateEndpointConnectionsClient, error) {
    36  	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	client := &ApplicationGatewayPrivateEndpointConnectionsClient{
    41  		subscriptionID: subscriptionID,
    42  		internal:       cl,
    43  	}
    44  	return client, nil
    45  }
    46  
    47  // BeginDelete - Deletes the specified private endpoint connection on application gateway.
    48  // If the operation fails it returns an *azcore.ResponseError type.
    49  //
    50  // Generated from API version 2024-05-01
    51  //   - resourceGroupName - The name of the resource group.
    52  //   - applicationGatewayName - The name of the application gateway.
    53  //   - connectionName - The name of the application gateway private endpoint connection.
    54  //   - options - ApplicationGatewayPrivateEndpointConnectionsClientBeginDeleteOptions contains the optional parameters for the
    55  //     ApplicationGatewayPrivateEndpointConnectionsClient.BeginDelete method.
    56  func (client *ApplicationGatewayPrivateEndpointConnectionsClient) BeginDelete(ctx context.Context, resourceGroupName string, applicationGatewayName string, connectionName string, options *ApplicationGatewayPrivateEndpointConnectionsClientBeginDeleteOptions) (*runtime.Poller[ApplicationGatewayPrivateEndpointConnectionsClientDeleteResponse], error) {
    57  	if options == nil || options.ResumeToken == "" {
    58  		resp, err := client.deleteOperation(ctx, resourceGroupName, applicationGatewayName, connectionName, options)
    59  		if err != nil {
    60  			return nil, err
    61  		}
    62  		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewayPrivateEndpointConnectionsClientDeleteResponse]{
    63  			FinalStateVia: runtime.FinalStateViaLocation,
    64  			Tracer:        client.internal.Tracer(),
    65  		})
    66  		return poller, err
    67  	} else {
    68  		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ApplicationGatewayPrivateEndpointConnectionsClientDeleteResponse]{
    69  			Tracer: client.internal.Tracer(),
    70  		})
    71  	}
    72  }
    73  
    74  // Delete - Deletes the specified private endpoint connection on application gateway.
    75  // If the operation fails it returns an *azcore.ResponseError type.
    76  //
    77  // Generated from API version 2024-05-01
    78  func (client *ApplicationGatewayPrivateEndpointConnectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, applicationGatewayName string, connectionName string, options *ApplicationGatewayPrivateEndpointConnectionsClientBeginDeleteOptions) (*http.Response, error) {
    79  	var err error
    80  	const operationName = "ApplicationGatewayPrivateEndpointConnectionsClient.BeginDelete"
    81  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
    82  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
    83  	defer func() { endSpan(err) }()
    84  	req, err := client.deleteCreateRequest(ctx, resourceGroupName, applicationGatewayName, connectionName, options)
    85  	if err != nil {
    86  		return nil, err
    87  	}
    88  	httpResp, err := client.internal.Pipeline().Do(req)
    89  	if err != nil {
    90  		return nil, err
    91  	}
    92  	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) {
    93  		err = runtime.NewResponseError(httpResp)
    94  		return nil, err
    95  	}
    96  	return httpResp, nil
    97  }
    98  
    99  // deleteCreateRequest creates the Delete request.
   100  func (client *ApplicationGatewayPrivateEndpointConnectionsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, applicationGatewayName string, connectionName string, options *ApplicationGatewayPrivateEndpointConnectionsClientBeginDeleteOptions) (*policy.Request, error) {
   101  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways/{applicationGatewayName}/privateEndpointConnections/{connectionName}"
   102  	if resourceGroupName == "" {
   103  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   104  	}
   105  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   106  	if applicationGatewayName == "" {
   107  		return nil, errors.New("parameter applicationGatewayName cannot be empty")
   108  	}
   109  	urlPath = strings.ReplaceAll(urlPath, "{applicationGatewayName}", url.PathEscape(applicationGatewayName))
   110  	if connectionName == "" {
   111  		return nil, errors.New("parameter connectionName cannot be empty")
   112  	}
   113  	urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName))
   114  	if client.subscriptionID == "" {
   115  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   116  	}
   117  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   118  	req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   119  	if err != nil {
   120  		return nil, err
   121  	}
   122  	reqQP := req.Raw().URL.Query()
   123  	reqQP.Set("api-version", "2024-05-01")
   124  	req.Raw().URL.RawQuery = reqQP.Encode()
   125  	req.Raw().Header["Accept"] = []string{"application/json"}
   126  	return req, nil
   127  }
   128  
   129  // Get - Gets the specified private endpoint connection on application gateway.
   130  // If the operation fails it returns an *azcore.ResponseError type.
   131  //
   132  // Generated from API version 2024-05-01
   133  //   - resourceGroupName - The name of the resource group.
   134  //   - applicationGatewayName - The name of the application gateway.
   135  //   - connectionName - The name of the application gateway private endpoint connection.
   136  //   - options - ApplicationGatewayPrivateEndpointConnectionsClientGetOptions contains the optional parameters for the ApplicationGatewayPrivateEndpointConnectionsClient.Get
   137  //     method.
   138  func (client *ApplicationGatewayPrivateEndpointConnectionsClient) Get(ctx context.Context, resourceGroupName string, applicationGatewayName string, connectionName string, options *ApplicationGatewayPrivateEndpointConnectionsClientGetOptions) (ApplicationGatewayPrivateEndpointConnectionsClientGetResponse, error) {
   139  	var err error
   140  	const operationName = "ApplicationGatewayPrivateEndpointConnectionsClient.Get"
   141  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   142  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   143  	defer func() { endSpan(err) }()
   144  	req, err := client.getCreateRequest(ctx, resourceGroupName, applicationGatewayName, connectionName, options)
   145  	if err != nil {
   146  		return ApplicationGatewayPrivateEndpointConnectionsClientGetResponse{}, err
   147  	}
   148  	httpResp, err := client.internal.Pipeline().Do(req)
   149  	if err != nil {
   150  		return ApplicationGatewayPrivateEndpointConnectionsClientGetResponse{}, err
   151  	}
   152  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
   153  		err = runtime.NewResponseError(httpResp)
   154  		return ApplicationGatewayPrivateEndpointConnectionsClientGetResponse{}, err
   155  	}
   156  	resp, err := client.getHandleResponse(httpResp)
   157  	return resp, err
   158  }
   159  
   160  // getCreateRequest creates the Get request.
   161  func (client *ApplicationGatewayPrivateEndpointConnectionsClient) getCreateRequest(ctx context.Context, resourceGroupName string, applicationGatewayName string, connectionName string, options *ApplicationGatewayPrivateEndpointConnectionsClientGetOptions) (*policy.Request, error) {
   162  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways/{applicationGatewayName}/privateEndpointConnections/{connectionName}"
   163  	if resourceGroupName == "" {
   164  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   165  	}
   166  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   167  	if applicationGatewayName == "" {
   168  		return nil, errors.New("parameter applicationGatewayName cannot be empty")
   169  	}
   170  	urlPath = strings.ReplaceAll(urlPath, "{applicationGatewayName}", url.PathEscape(applicationGatewayName))
   171  	if connectionName == "" {
   172  		return nil, errors.New("parameter connectionName cannot be empty")
   173  	}
   174  	urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName))
   175  	if client.subscriptionID == "" {
   176  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   177  	}
   178  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   179  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   180  	if err != nil {
   181  		return nil, err
   182  	}
   183  	reqQP := req.Raw().URL.Query()
   184  	reqQP.Set("api-version", "2024-05-01")
   185  	req.Raw().URL.RawQuery = reqQP.Encode()
   186  	req.Raw().Header["Accept"] = []string{"application/json"}
   187  	return req, nil
   188  }
   189  
   190  // getHandleResponse handles the Get response.
   191  func (client *ApplicationGatewayPrivateEndpointConnectionsClient) getHandleResponse(resp *http.Response) (ApplicationGatewayPrivateEndpointConnectionsClientGetResponse, error) {
   192  	result := ApplicationGatewayPrivateEndpointConnectionsClientGetResponse{}
   193  	if err := runtime.UnmarshalAsJSON(resp, &result.ApplicationGatewayPrivateEndpointConnection); err != nil {
   194  		return ApplicationGatewayPrivateEndpointConnectionsClientGetResponse{}, err
   195  	}
   196  	return result, nil
   197  }
   198  
   199  // NewListPager - Lists all private endpoint connections on an application gateway.
   200  //
   201  // Generated from API version 2024-05-01
   202  //   - resourceGroupName - The name of the resource group.
   203  //   - applicationGatewayName - The name of the application gateway.
   204  //   - options - ApplicationGatewayPrivateEndpointConnectionsClientListOptions contains the optional parameters for the ApplicationGatewayPrivateEndpointConnectionsClient.NewListPager
   205  //     method.
   206  func (client *ApplicationGatewayPrivateEndpointConnectionsClient) NewListPager(resourceGroupName string, applicationGatewayName string, options *ApplicationGatewayPrivateEndpointConnectionsClientListOptions) *runtime.Pager[ApplicationGatewayPrivateEndpointConnectionsClientListResponse] {
   207  	return runtime.NewPager(runtime.PagingHandler[ApplicationGatewayPrivateEndpointConnectionsClientListResponse]{
   208  		More: func(page ApplicationGatewayPrivateEndpointConnectionsClientListResponse) bool {
   209  			return page.NextLink != nil && len(*page.NextLink) > 0
   210  		},
   211  		Fetcher: func(ctx context.Context, page *ApplicationGatewayPrivateEndpointConnectionsClientListResponse) (ApplicationGatewayPrivateEndpointConnectionsClientListResponse, error) {
   212  			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ApplicationGatewayPrivateEndpointConnectionsClient.NewListPager")
   213  			nextLink := ""
   214  			if page != nil {
   215  				nextLink = *page.NextLink
   216  			}
   217  			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
   218  				return client.listCreateRequest(ctx, resourceGroupName, applicationGatewayName, options)
   219  			}, nil)
   220  			if err != nil {
   221  				return ApplicationGatewayPrivateEndpointConnectionsClientListResponse{}, err
   222  			}
   223  			return client.listHandleResponse(resp)
   224  		},
   225  		Tracer: client.internal.Tracer(),
   226  	})
   227  }
   228  
   229  // listCreateRequest creates the List request.
   230  func (client *ApplicationGatewayPrivateEndpointConnectionsClient) listCreateRequest(ctx context.Context, resourceGroupName string, applicationGatewayName string, options *ApplicationGatewayPrivateEndpointConnectionsClientListOptions) (*policy.Request, error) {
   231  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways/{applicationGatewayName}/privateEndpointConnections"
   232  	if resourceGroupName == "" {
   233  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   234  	}
   235  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   236  	if applicationGatewayName == "" {
   237  		return nil, errors.New("parameter applicationGatewayName cannot be empty")
   238  	}
   239  	urlPath = strings.ReplaceAll(urlPath, "{applicationGatewayName}", url.PathEscape(applicationGatewayName))
   240  	if client.subscriptionID == "" {
   241  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   242  	}
   243  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   244  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   245  	if err != nil {
   246  		return nil, err
   247  	}
   248  	reqQP := req.Raw().URL.Query()
   249  	reqQP.Set("api-version", "2024-05-01")
   250  	req.Raw().URL.RawQuery = reqQP.Encode()
   251  	req.Raw().Header["Accept"] = []string{"application/json"}
   252  	return req, nil
   253  }
   254  
   255  // listHandleResponse handles the List response.
   256  func (client *ApplicationGatewayPrivateEndpointConnectionsClient) listHandleResponse(resp *http.Response) (ApplicationGatewayPrivateEndpointConnectionsClientListResponse, error) {
   257  	result := ApplicationGatewayPrivateEndpointConnectionsClientListResponse{}
   258  	if err := runtime.UnmarshalAsJSON(resp, &result.ApplicationGatewayPrivateEndpointConnectionListResult); err != nil {
   259  		return ApplicationGatewayPrivateEndpointConnectionsClientListResponse{}, err
   260  	}
   261  	return result, nil
   262  }
   263  
   264  // BeginUpdate - Updates the specified private endpoint connection on application gateway.
   265  // If the operation fails it returns an *azcore.ResponseError type.
   266  //
   267  // Generated from API version 2024-05-01
   268  //   - resourceGroupName - The name of the resource group.
   269  //   - applicationGatewayName - The name of the application gateway.
   270  //   - connectionName - The name of the application gateway private endpoint connection.
   271  //   - parameters - Parameters supplied to update application gateway private endpoint connection operation.
   272  //   - options - ApplicationGatewayPrivateEndpointConnectionsClientBeginUpdateOptions contains the optional parameters for the
   273  //     ApplicationGatewayPrivateEndpointConnectionsClient.BeginUpdate method.
   274  func (client *ApplicationGatewayPrivateEndpointConnectionsClient) BeginUpdate(ctx context.Context, resourceGroupName string, applicationGatewayName string, connectionName string, parameters ApplicationGatewayPrivateEndpointConnection, options *ApplicationGatewayPrivateEndpointConnectionsClientBeginUpdateOptions) (*runtime.Poller[ApplicationGatewayPrivateEndpointConnectionsClientUpdateResponse], error) {
   275  	if options == nil || options.ResumeToken == "" {
   276  		resp, err := client.update(ctx, resourceGroupName, applicationGatewayName, connectionName, parameters, options)
   277  		if err != nil {
   278  			return nil, err
   279  		}
   280  		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ApplicationGatewayPrivateEndpointConnectionsClientUpdateResponse]{
   281  			FinalStateVia: runtime.FinalStateViaAzureAsyncOp,
   282  			Tracer:        client.internal.Tracer(),
   283  		})
   284  		return poller, err
   285  	} else {
   286  		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ApplicationGatewayPrivateEndpointConnectionsClientUpdateResponse]{
   287  			Tracer: client.internal.Tracer(),
   288  		})
   289  	}
   290  }
   291  
   292  // Update - Updates the specified private endpoint connection on application gateway.
   293  // If the operation fails it returns an *azcore.ResponseError type.
   294  //
   295  // Generated from API version 2024-05-01
   296  func (client *ApplicationGatewayPrivateEndpointConnectionsClient) update(ctx context.Context, resourceGroupName string, applicationGatewayName string, connectionName string, parameters ApplicationGatewayPrivateEndpointConnection, options *ApplicationGatewayPrivateEndpointConnectionsClientBeginUpdateOptions) (*http.Response, error) {
   297  	var err error
   298  	const operationName = "ApplicationGatewayPrivateEndpointConnectionsClient.BeginUpdate"
   299  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   300  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   301  	defer func() { endSpan(err) }()
   302  	req, err := client.updateCreateRequest(ctx, resourceGroupName, applicationGatewayName, connectionName, parameters, options)
   303  	if err != nil {
   304  		return nil, err
   305  	}
   306  	httpResp, err := client.internal.Pipeline().Do(req)
   307  	if err != nil {
   308  		return nil, err
   309  	}
   310  	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) {
   311  		err = runtime.NewResponseError(httpResp)
   312  		return nil, err
   313  	}
   314  	return httpResp, nil
   315  }
   316  
   317  // updateCreateRequest creates the Update request.
   318  func (client *ApplicationGatewayPrivateEndpointConnectionsClient) updateCreateRequest(ctx context.Context, resourceGroupName string, applicationGatewayName string, connectionName string, parameters ApplicationGatewayPrivateEndpointConnection, options *ApplicationGatewayPrivateEndpointConnectionsClientBeginUpdateOptions) (*policy.Request, error) {
   319  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways/{applicationGatewayName}/privateEndpointConnections/{connectionName}"
   320  	if resourceGroupName == "" {
   321  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   322  	}
   323  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   324  	if applicationGatewayName == "" {
   325  		return nil, errors.New("parameter applicationGatewayName cannot be empty")
   326  	}
   327  	urlPath = strings.ReplaceAll(urlPath, "{applicationGatewayName}", url.PathEscape(applicationGatewayName))
   328  	if connectionName == "" {
   329  		return nil, errors.New("parameter connectionName cannot be empty")
   330  	}
   331  	urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName))
   332  	if client.subscriptionID == "" {
   333  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   334  	}
   335  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   336  	req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   337  	if err != nil {
   338  		return nil, err
   339  	}
   340  	reqQP := req.Raw().URL.Query()
   341  	reqQP.Set("api-version", "2024-05-01")
   342  	req.Raw().URL.RawQuery = reqQP.Encode()
   343  	req.Raw().Header["Accept"] = []string{"application/json"}
   344  	if err := runtime.MarshalAsJSON(req, parameters); err != nil {
   345  		return nil, err
   346  	}
   347  	return req, nil
   348  }