github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/expressrouteconnections_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  // ExpressRouteConnectionsClient contains the methods for the ExpressRouteConnections group.
    24  // Don't use this type directly, use NewExpressRouteConnectionsClient() instead.
    25  type ExpressRouteConnectionsClient struct {
    26  	internal       *arm.Client
    27  	subscriptionID string
    28  }
    29  
    30  // NewExpressRouteConnectionsClient creates a new instance of ExpressRouteConnectionsClient 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 NewExpressRouteConnectionsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ExpressRouteConnectionsClient, error) {
    36  	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	client := &ExpressRouteConnectionsClient{
    41  		subscriptionID: subscriptionID,
    42  		internal:       cl,
    43  	}
    44  	return client, nil
    45  }
    46  
    47  // BeginCreateOrUpdate - Creates a connection between an ExpressRoute gateway and an ExpressRoute circuit.
    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  //   - expressRouteGatewayName - The name of the ExpressRoute gateway.
    53  //   - connectionName - The name of the connection subresource.
    54  //   - putExpressRouteConnectionParameters - Parameters required in an ExpressRouteConnection PUT operation.
    55  //   - options - ExpressRouteConnectionsClientBeginCreateOrUpdateOptions contains the optional parameters for the ExpressRouteConnectionsClient.BeginCreateOrUpdate
    56  //     method.
    57  func (client *ExpressRouteConnectionsClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, putExpressRouteConnectionParameters ExpressRouteConnection, options *ExpressRouteConnectionsClientBeginCreateOrUpdateOptions) (*runtime.Poller[ExpressRouteConnectionsClientCreateOrUpdateResponse], error) {
    58  	if options == nil || options.ResumeToken == "" {
    59  		resp, err := client.createOrUpdate(ctx, resourceGroupName, expressRouteGatewayName, connectionName, putExpressRouteConnectionParameters, options)
    60  		if err != nil {
    61  			return nil, err
    62  		}
    63  		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteConnectionsClientCreateOrUpdateResponse]{
    64  			FinalStateVia: runtime.FinalStateViaAzureAsyncOp,
    65  			Tracer:        client.internal.Tracer(),
    66  		})
    67  		return poller, err
    68  	} else {
    69  		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ExpressRouteConnectionsClientCreateOrUpdateResponse]{
    70  			Tracer: client.internal.Tracer(),
    71  		})
    72  	}
    73  }
    74  
    75  // CreateOrUpdate - Creates a connection between an ExpressRoute gateway and an ExpressRoute circuit.
    76  // If the operation fails it returns an *azcore.ResponseError type.
    77  //
    78  // Generated from API version 2024-05-01
    79  func (client *ExpressRouteConnectionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, putExpressRouteConnectionParameters ExpressRouteConnection, options *ExpressRouteConnectionsClientBeginCreateOrUpdateOptions) (*http.Response, error) {
    80  	var err error
    81  	const operationName = "ExpressRouteConnectionsClient.BeginCreateOrUpdate"
    82  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
    83  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
    84  	defer func() { endSpan(err) }()
    85  	req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, expressRouteGatewayName, connectionName, putExpressRouteConnectionParameters, options)
    86  	if err != nil {
    87  		return nil, err
    88  	}
    89  	httpResp, err := client.internal.Pipeline().Do(req)
    90  	if err != nil {
    91  		return nil, err
    92  	}
    93  	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) {
    94  		err = runtime.NewResponseError(httpResp)
    95  		return nil, err
    96  	}
    97  	return httpResp, nil
    98  }
    99  
   100  // createOrUpdateCreateRequest creates the CreateOrUpdate request.
   101  func (client *ExpressRouteConnectionsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, putExpressRouteConnectionParameters ExpressRouteConnection, options *ExpressRouteConnectionsClientBeginCreateOrUpdateOptions) (*policy.Request, error) {
   102  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}/expressRouteConnections/{connectionName}"
   103  	if resourceGroupName == "" {
   104  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   105  	}
   106  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   107  	if expressRouteGatewayName == "" {
   108  		return nil, errors.New("parameter expressRouteGatewayName cannot be empty")
   109  	}
   110  	urlPath = strings.ReplaceAll(urlPath, "{expressRouteGatewayName}", url.PathEscape(expressRouteGatewayName))
   111  	if connectionName == "" {
   112  		return nil, errors.New("parameter connectionName cannot be empty")
   113  	}
   114  	urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName))
   115  	if client.subscriptionID == "" {
   116  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   117  	}
   118  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   119  	req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   120  	if err != nil {
   121  		return nil, err
   122  	}
   123  	reqQP := req.Raw().URL.Query()
   124  	reqQP.Set("api-version", "2024-05-01")
   125  	req.Raw().URL.RawQuery = reqQP.Encode()
   126  	req.Raw().Header["Accept"] = []string{"application/json"}
   127  	if err := runtime.MarshalAsJSON(req, putExpressRouteConnectionParameters); err != nil {
   128  		return nil, err
   129  	}
   130  	return req, nil
   131  }
   132  
   133  // BeginDelete - Deletes a connection to a ExpressRoute circuit.
   134  // If the operation fails it returns an *azcore.ResponseError type.
   135  //
   136  // Generated from API version 2024-05-01
   137  //   - resourceGroupName - The name of the resource group.
   138  //   - expressRouteGatewayName - The name of the ExpressRoute gateway.
   139  //   - connectionName - The name of the connection subresource.
   140  //   - options - ExpressRouteConnectionsClientBeginDeleteOptions contains the optional parameters for the ExpressRouteConnectionsClient.BeginDelete
   141  //     method.
   142  func (client *ExpressRouteConnectionsClient) BeginDelete(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, options *ExpressRouteConnectionsClientBeginDeleteOptions) (*runtime.Poller[ExpressRouteConnectionsClientDeleteResponse], error) {
   143  	if options == nil || options.ResumeToken == "" {
   144  		resp, err := client.deleteOperation(ctx, resourceGroupName, expressRouteGatewayName, connectionName, options)
   145  		if err != nil {
   146  			return nil, err
   147  		}
   148  		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ExpressRouteConnectionsClientDeleteResponse]{
   149  			FinalStateVia: runtime.FinalStateViaLocation,
   150  			Tracer:        client.internal.Tracer(),
   151  		})
   152  		return poller, err
   153  	} else {
   154  		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ExpressRouteConnectionsClientDeleteResponse]{
   155  			Tracer: client.internal.Tracer(),
   156  		})
   157  	}
   158  }
   159  
   160  // Delete - Deletes a connection to a ExpressRoute circuit.
   161  // If the operation fails it returns an *azcore.ResponseError type.
   162  //
   163  // Generated from API version 2024-05-01
   164  func (client *ExpressRouteConnectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, options *ExpressRouteConnectionsClientBeginDeleteOptions) (*http.Response, error) {
   165  	var err error
   166  	const operationName = "ExpressRouteConnectionsClient.BeginDelete"
   167  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   168  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   169  	defer func() { endSpan(err) }()
   170  	req, err := client.deleteCreateRequest(ctx, resourceGroupName, expressRouteGatewayName, connectionName, options)
   171  	if err != nil {
   172  		return nil, err
   173  	}
   174  	httpResp, err := client.internal.Pipeline().Do(req)
   175  	if err != nil {
   176  		return nil, err
   177  	}
   178  	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) {
   179  		err = runtime.NewResponseError(httpResp)
   180  		return nil, err
   181  	}
   182  	return httpResp, nil
   183  }
   184  
   185  // deleteCreateRequest creates the Delete request.
   186  func (client *ExpressRouteConnectionsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, options *ExpressRouteConnectionsClientBeginDeleteOptions) (*policy.Request, error) {
   187  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}/expressRouteConnections/{connectionName}"
   188  	if resourceGroupName == "" {
   189  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   190  	}
   191  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   192  	if expressRouteGatewayName == "" {
   193  		return nil, errors.New("parameter expressRouteGatewayName cannot be empty")
   194  	}
   195  	urlPath = strings.ReplaceAll(urlPath, "{expressRouteGatewayName}", url.PathEscape(expressRouteGatewayName))
   196  	if connectionName == "" {
   197  		return nil, errors.New("parameter connectionName cannot be empty")
   198  	}
   199  	urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName))
   200  	if client.subscriptionID == "" {
   201  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   202  	}
   203  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   204  	req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   205  	if err != nil {
   206  		return nil, err
   207  	}
   208  	reqQP := req.Raw().URL.Query()
   209  	reqQP.Set("api-version", "2024-05-01")
   210  	req.Raw().URL.RawQuery = reqQP.Encode()
   211  	req.Raw().Header["Accept"] = []string{"application/json"}
   212  	return req, nil
   213  }
   214  
   215  // Get - Gets the specified ExpressRouteConnection.
   216  // If the operation fails it returns an *azcore.ResponseError type.
   217  //
   218  // Generated from API version 2024-05-01
   219  //   - resourceGroupName - The name of the resource group.
   220  //   - expressRouteGatewayName - The name of the ExpressRoute gateway.
   221  //   - connectionName - The name of the ExpressRoute connection.
   222  //   - options - ExpressRouteConnectionsClientGetOptions contains the optional parameters for the ExpressRouteConnectionsClient.Get
   223  //     method.
   224  func (client *ExpressRouteConnectionsClient) Get(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, options *ExpressRouteConnectionsClientGetOptions) (ExpressRouteConnectionsClientGetResponse, error) {
   225  	var err error
   226  	const operationName = "ExpressRouteConnectionsClient.Get"
   227  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   228  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   229  	defer func() { endSpan(err) }()
   230  	req, err := client.getCreateRequest(ctx, resourceGroupName, expressRouteGatewayName, connectionName, options)
   231  	if err != nil {
   232  		return ExpressRouteConnectionsClientGetResponse{}, err
   233  	}
   234  	httpResp, err := client.internal.Pipeline().Do(req)
   235  	if err != nil {
   236  		return ExpressRouteConnectionsClientGetResponse{}, err
   237  	}
   238  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
   239  		err = runtime.NewResponseError(httpResp)
   240  		return ExpressRouteConnectionsClientGetResponse{}, err
   241  	}
   242  	resp, err := client.getHandleResponse(httpResp)
   243  	return resp, err
   244  }
   245  
   246  // getCreateRequest creates the Get request.
   247  func (client *ExpressRouteConnectionsClient) getCreateRequest(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, connectionName string, options *ExpressRouteConnectionsClientGetOptions) (*policy.Request, error) {
   248  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}/expressRouteConnections/{connectionName}"
   249  	if resourceGroupName == "" {
   250  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   251  	}
   252  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   253  	if expressRouteGatewayName == "" {
   254  		return nil, errors.New("parameter expressRouteGatewayName cannot be empty")
   255  	}
   256  	urlPath = strings.ReplaceAll(urlPath, "{expressRouteGatewayName}", url.PathEscape(expressRouteGatewayName))
   257  	if connectionName == "" {
   258  		return nil, errors.New("parameter connectionName cannot be empty")
   259  	}
   260  	urlPath = strings.ReplaceAll(urlPath, "{connectionName}", url.PathEscape(connectionName))
   261  	if client.subscriptionID == "" {
   262  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   263  	}
   264  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   265  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   266  	if err != nil {
   267  		return nil, err
   268  	}
   269  	reqQP := req.Raw().URL.Query()
   270  	reqQP.Set("api-version", "2024-05-01")
   271  	req.Raw().URL.RawQuery = reqQP.Encode()
   272  	req.Raw().Header["Accept"] = []string{"application/json"}
   273  	return req, nil
   274  }
   275  
   276  // getHandleResponse handles the Get response.
   277  func (client *ExpressRouteConnectionsClient) getHandleResponse(resp *http.Response) (ExpressRouteConnectionsClientGetResponse, error) {
   278  	result := ExpressRouteConnectionsClientGetResponse{}
   279  	if err := runtime.UnmarshalAsJSON(resp, &result.ExpressRouteConnection); err != nil {
   280  		return ExpressRouteConnectionsClientGetResponse{}, err
   281  	}
   282  	return result, nil
   283  }
   284  
   285  // List - Lists ExpressRouteConnections.
   286  // If the operation fails it returns an *azcore.ResponseError type.
   287  //
   288  // Generated from API version 2024-05-01
   289  //   - resourceGroupName - The name of the resource group.
   290  //   - expressRouteGatewayName - The name of the ExpressRoute gateway.
   291  //   - options - ExpressRouteConnectionsClientListOptions contains the optional parameters for the ExpressRouteConnectionsClient.List
   292  //     method.
   293  func (client *ExpressRouteConnectionsClient) List(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, options *ExpressRouteConnectionsClientListOptions) (ExpressRouteConnectionsClientListResponse, error) {
   294  	var err error
   295  	const operationName = "ExpressRouteConnectionsClient.List"
   296  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   297  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   298  	defer func() { endSpan(err) }()
   299  	req, err := client.listCreateRequest(ctx, resourceGroupName, expressRouteGatewayName, options)
   300  	if err != nil {
   301  		return ExpressRouteConnectionsClientListResponse{}, err
   302  	}
   303  	httpResp, err := client.internal.Pipeline().Do(req)
   304  	if err != nil {
   305  		return ExpressRouteConnectionsClientListResponse{}, err
   306  	}
   307  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
   308  		err = runtime.NewResponseError(httpResp)
   309  		return ExpressRouteConnectionsClientListResponse{}, err
   310  	}
   311  	resp, err := client.listHandleResponse(httpResp)
   312  	return resp, err
   313  }
   314  
   315  // listCreateRequest creates the List request.
   316  func (client *ExpressRouteConnectionsClient) listCreateRequest(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, options *ExpressRouteConnectionsClientListOptions) (*policy.Request, error) {
   317  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}/expressRouteConnections"
   318  	if resourceGroupName == "" {
   319  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   320  	}
   321  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   322  	if expressRouteGatewayName == "" {
   323  		return nil, errors.New("parameter expressRouteGatewayName cannot be empty")
   324  	}
   325  	urlPath = strings.ReplaceAll(urlPath, "{expressRouteGatewayName}", url.PathEscape(expressRouteGatewayName))
   326  	if client.subscriptionID == "" {
   327  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   328  	}
   329  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   330  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   331  	if err != nil {
   332  		return nil, err
   333  	}
   334  	reqQP := req.Raw().URL.Query()
   335  	reqQP.Set("api-version", "2024-05-01")
   336  	req.Raw().URL.RawQuery = reqQP.Encode()
   337  	req.Raw().Header["Accept"] = []string{"application/json"}
   338  	return req, nil
   339  }
   340  
   341  // listHandleResponse handles the List response.
   342  func (client *ExpressRouteConnectionsClient) listHandleResponse(resp *http.Response) (ExpressRouteConnectionsClientListResponse, error) {
   343  	result := ExpressRouteConnectionsClientListResponse{}
   344  	if err := runtime.UnmarshalAsJSON(resp, &result.ExpressRouteConnectionList); err != nil {
   345  		return ExpressRouteConnectionsClientListResponse{}, err
   346  	}
   347  	return result, nil
   348  }