github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/localnetworkgateways_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  // LocalNetworkGatewaysClient contains the methods for the LocalNetworkGateways group.
    24  // Don't use this type directly, use NewLocalNetworkGatewaysClient() instead.
    25  type LocalNetworkGatewaysClient struct {
    26  	internal       *arm.Client
    27  	subscriptionID string
    28  }
    29  
    30  // NewLocalNetworkGatewaysClient creates a new instance of LocalNetworkGatewaysClient 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 NewLocalNetworkGatewaysClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*LocalNetworkGatewaysClient, error) {
    36  	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	client := &LocalNetworkGatewaysClient{
    41  		subscriptionID: subscriptionID,
    42  		internal:       cl,
    43  	}
    44  	return client, nil
    45  }
    46  
    47  // BeginCreateOrUpdate - Creates or updates a local network gateway in the specified resource group.
    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  //   - localNetworkGatewayName - The name of the local network gateway.
    53  //   - parameters - Parameters supplied to the create or update local network gateway operation.
    54  //   - options - LocalNetworkGatewaysClientBeginCreateOrUpdateOptions contains the optional parameters for the LocalNetworkGatewaysClient.BeginCreateOrUpdate
    55  //     method.
    56  func (client *LocalNetworkGatewaysClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, parameters LocalNetworkGateway, options *LocalNetworkGatewaysClientBeginCreateOrUpdateOptions) (*runtime.Poller[LocalNetworkGatewaysClientCreateOrUpdateResponse], error) {
    57  	if options == nil || options.ResumeToken == "" {
    58  		resp, err := client.createOrUpdate(ctx, resourceGroupName, localNetworkGatewayName, parameters, options)
    59  		if err != nil {
    60  			return nil, err
    61  		}
    62  		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LocalNetworkGatewaysClientCreateOrUpdateResponse]{
    63  			FinalStateVia: runtime.FinalStateViaAzureAsyncOp,
    64  			Tracer:        client.internal.Tracer(),
    65  		})
    66  		return poller, err
    67  	} else {
    68  		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[LocalNetworkGatewaysClientCreateOrUpdateResponse]{
    69  			Tracer: client.internal.Tracer(),
    70  		})
    71  	}
    72  }
    73  
    74  // CreateOrUpdate - Creates or updates a local network gateway in the specified resource group.
    75  // If the operation fails it returns an *azcore.ResponseError type.
    76  //
    77  // Generated from API version 2024-05-01
    78  func (client *LocalNetworkGatewaysClient) createOrUpdate(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, parameters LocalNetworkGateway, options *LocalNetworkGatewaysClientBeginCreateOrUpdateOptions) (*http.Response, error) {
    79  	var err error
    80  	const operationName = "LocalNetworkGatewaysClient.BeginCreateOrUpdate"
    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.createOrUpdateCreateRequest(ctx, resourceGroupName, localNetworkGatewayName, parameters, 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.StatusCreated) {
    93  		err = runtime.NewResponseError(httpResp)
    94  		return nil, err
    95  	}
    96  	return httpResp, nil
    97  }
    98  
    99  // createOrUpdateCreateRequest creates the CreateOrUpdate request.
   100  func (client *LocalNetworkGatewaysClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, parameters LocalNetworkGateway, options *LocalNetworkGatewaysClientBeginCreateOrUpdateOptions) (*policy.Request, error) {
   101  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/localNetworkGateways/{localNetworkGatewayName}"
   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 localNetworkGatewayName == "" {
   107  		return nil, errors.New("parameter localNetworkGatewayName cannot be empty")
   108  	}
   109  	urlPath = strings.ReplaceAll(urlPath, "{localNetworkGatewayName}", url.PathEscape(localNetworkGatewayName))
   110  	if client.subscriptionID == "" {
   111  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   112  	}
   113  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   114  	req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   115  	if err != nil {
   116  		return nil, err
   117  	}
   118  	reqQP := req.Raw().URL.Query()
   119  	reqQP.Set("api-version", "2024-05-01")
   120  	req.Raw().URL.RawQuery = reqQP.Encode()
   121  	req.Raw().Header["Accept"] = []string{"application/json"}
   122  	if err := runtime.MarshalAsJSON(req, parameters); err != nil {
   123  		return nil, err
   124  	}
   125  	return req, nil
   126  }
   127  
   128  // BeginDelete - Deletes the specified local network gateway.
   129  // If the operation fails it returns an *azcore.ResponseError type.
   130  //
   131  // Generated from API version 2024-05-01
   132  //   - resourceGroupName - The name of the resource group.
   133  //   - localNetworkGatewayName - The name of the local network gateway.
   134  //   - options - LocalNetworkGatewaysClientBeginDeleteOptions contains the optional parameters for the LocalNetworkGatewaysClient.BeginDelete
   135  //     method.
   136  func (client *LocalNetworkGatewaysClient) BeginDelete(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, options *LocalNetworkGatewaysClientBeginDeleteOptions) (*runtime.Poller[LocalNetworkGatewaysClientDeleteResponse], error) {
   137  	if options == nil || options.ResumeToken == "" {
   138  		resp, err := client.deleteOperation(ctx, resourceGroupName, localNetworkGatewayName, options)
   139  		if err != nil {
   140  			return nil, err
   141  		}
   142  		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LocalNetworkGatewaysClientDeleteResponse]{
   143  			FinalStateVia: runtime.FinalStateViaLocation,
   144  			Tracer:        client.internal.Tracer(),
   145  		})
   146  		return poller, err
   147  	} else {
   148  		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[LocalNetworkGatewaysClientDeleteResponse]{
   149  			Tracer: client.internal.Tracer(),
   150  		})
   151  	}
   152  }
   153  
   154  // Delete - Deletes the specified local network gateway.
   155  // If the operation fails it returns an *azcore.ResponseError type.
   156  //
   157  // Generated from API version 2024-05-01
   158  func (client *LocalNetworkGatewaysClient) deleteOperation(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, options *LocalNetworkGatewaysClientBeginDeleteOptions) (*http.Response, error) {
   159  	var err error
   160  	const operationName = "LocalNetworkGatewaysClient.BeginDelete"
   161  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   162  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   163  	defer func() { endSpan(err) }()
   164  	req, err := client.deleteCreateRequest(ctx, resourceGroupName, localNetworkGatewayName, options)
   165  	if err != nil {
   166  		return nil, err
   167  	}
   168  	httpResp, err := client.internal.Pipeline().Do(req)
   169  	if err != nil {
   170  		return nil, err
   171  	}
   172  	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) {
   173  		err = runtime.NewResponseError(httpResp)
   174  		return nil, err
   175  	}
   176  	return httpResp, nil
   177  }
   178  
   179  // deleteCreateRequest creates the Delete request.
   180  func (client *LocalNetworkGatewaysClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, options *LocalNetworkGatewaysClientBeginDeleteOptions) (*policy.Request, error) {
   181  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/localNetworkGateways/{localNetworkGatewayName}"
   182  	if resourceGroupName == "" {
   183  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   184  	}
   185  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   186  	if localNetworkGatewayName == "" {
   187  		return nil, errors.New("parameter localNetworkGatewayName cannot be empty")
   188  	}
   189  	urlPath = strings.ReplaceAll(urlPath, "{localNetworkGatewayName}", url.PathEscape(localNetworkGatewayName))
   190  	if client.subscriptionID == "" {
   191  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   192  	}
   193  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   194  	req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   195  	if err != nil {
   196  		return nil, err
   197  	}
   198  	reqQP := req.Raw().URL.Query()
   199  	reqQP.Set("api-version", "2024-05-01")
   200  	req.Raw().URL.RawQuery = reqQP.Encode()
   201  	req.Raw().Header["Accept"] = []string{"application/json"}
   202  	return req, nil
   203  }
   204  
   205  // Get - Gets the specified local network gateway in a resource group.
   206  // If the operation fails it returns an *azcore.ResponseError type.
   207  //
   208  // Generated from API version 2024-05-01
   209  //   - resourceGroupName - The name of the resource group.
   210  //   - localNetworkGatewayName - The name of the local network gateway.
   211  //   - options - LocalNetworkGatewaysClientGetOptions contains the optional parameters for the LocalNetworkGatewaysClient.Get
   212  //     method.
   213  func (client *LocalNetworkGatewaysClient) Get(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, options *LocalNetworkGatewaysClientGetOptions) (LocalNetworkGatewaysClientGetResponse, error) {
   214  	var err error
   215  	const operationName = "LocalNetworkGatewaysClient.Get"
   216  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   217  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   218  	defer func() { endSpan(err) }()
   219  	req, err := client.getCreateRequest(ctx, resourceGroupName, localNetworkGatewayName, options)
   220  	if err != nil {
   221  		return LocalNetworkGatewaysClientGetResponse{}, err
   222  	}
   223  	httpResp, err := client.internal.Pipeline().Do(req)
   224  	if err != nil {
   225  		return LocalNetworkGatewaysClientGetResponse{}, err
   226  	}
   227  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
   228  		err = runtime.NewResponseError(httpResp)
   229  		return LocalNetworkGatewaysClientGetResponse{}, err
   230  	}
   231  	resp, err := client.getHandleResponse(httpResp)
   232  	return resp, err
   233  }
   234  
   235  // getCreateRequest creates the Get request.
   236  func (client *LocalNetworkGatewaysClient) getCreateRequest(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, options *LocalNetworkGatewaysClientGetOptions) (*policy.Request, error) {
   237  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/localNetworkGateways/{localNetworkGatewayName}"
   238  	if resourceGroupName == "" {
   239  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   240  	}
   241  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   242  	if localNetworkGatewayName == "" {
   243  		return nil, errors.New("parameter localNetworkGatewayName cannot be empty")
   244  	}
   245  	urlPath = strings.ReplaceAll(urlPath, "{localNetworkGatewayName}", url.PathEscape(localNetworkGatewayName))
   246  	if client.subscriptionID == "" {
   247  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   248  	}
   249  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   250  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   251  	if err != nil {
   252  		return nil, err
   253  	}
   254  	reqQP := req.Raw().URL.Query()
   255  	reqQP.Set("api-version", "2024-05-01")
   256  	req.Raw().URL.RawQuery = reqQP.Encode()
   257  	req.Raw().Header["Accept"] = []string{"application/json"}
   258  	return req, nil
   259  }
   260  
   261  // getHandleResponse handles the Get response.
   262  func (client *LocalNetworkGatewaysClient) getHandleResponse(resp *http.Response) (LocalNetworkGatewaysClientGetResponse, error) {
   263  	result := LocalNetworkGatewaysClientGetResponse{}
   264  	if err := runtime.UnmarshalAsJSON(resp, &result.LocalNetworkGateway); err != nil {
   265  		return LocalNetworkGatewaysClientGetResponse{}, err
   266  	}
   267  	return result, nil
   268  }
   269  
   270  // NewListPager - Gets all the local network gateways in a resource group.
   271  //
   272  // Generated from API version 2024-05-01
   273  //   - resourceGroupName - The name of the resource group.
   274  //   - options - LocalNetworkGatewaysClientListOptions contains the optional parameters for the LocalNetworkGatewaysClient.NewListPager
   275  //     method.
   276  func (client *LocalNetworkGatewaysClient) NewListPager(resourceGroupName string, options *LocalNetworkGatewaysClientListOptions) *runtime.Pager[LocalNetworkGatewaysClientListResponse] {
   277  	return runtime.NewPager(runtime.PagingHandler[LocalNetworkGatewaysClientListResponse]{
   278  		More: func(page LocalNetworkGatewaysClientListResponse) bool {
   279  			return page.NextLink != nil && len(*page.NextLink) > 0
   280  		},
   281  		Fetcher: func(ctx context.Context, page *LocalNetworkGatewaysClientListResponse) (LocalNetworkGatewaysClientListResponse, error) {
   282  			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "LocalNetworkGatewaysClient.NewListPager")
   283  			nextLink := ""
   284  			if page != nil {
   285  				nextLink = *page.NextLink
   286  			}
   287  			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
   288  				return client.listCreateRequest(ctx, resourceGroupName, options)
   289  			}, nil)
   290  			if err != nil {
   291  				return LocalNetworkGatewaysClientListResponse{}, err
   292  			}
   293  			return client.listHandleResponse(resp)
   294  		},
   295  		Tracer: client.internal.Tracer(),
   296  	})
   297  }
   298  
   299  // listCreateRequest creates the List request.
   300  func (client *LocalNetworkGatewaysClient) listCreateRequest(ctx context.Context, resourceGroupName string, options *LocalNetworkGatewaysClientListOptions) (*policy.Request, error) {
   301  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/localNetworkGateways"
   302  	if resourceGroupName == "" {
   303  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   304  	}
   305  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   306  	if client.subscriptionID == "" {
   307  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   308  	}
   309  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   310  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   311  	if err != nil {
   312  		return nil, err
   313  	}
   314  	reqQP := req.Raw().URL.Query()
   315  	reqQP.Set("api-version", "2024-05-01")
   316  	req.Raw().URL.RawQuery = reqQP.Encode()
   317  	req.Raw().Header["Accept"] = []string{"application/json"}
   318  	return req, nil
   319  }
   320  
   321  // listHandleResponse handles the List response.
   322  func (client *LocalNetworkGatewaysClient) listHandleResponse(resp *http.Response) (LocalNetworkGatewaysClientListResponse, error) {
   323  	result := LocalNetworkGatewaysClientListResponse{}
   324  	if err := runtime.UnmarshalAsJSON(resp, &result.LocalNetworkGatewayListResult); err != nil {
   325  		return LocalNetworkGatewaysClientListResponse{}, err
   326  	}
   327  	return result, nil
   328  }
   329  
   330  // UpdateTags - Updates a local network gateway tags.
   331  // If the operation fails it returns an *azcore.ResponseError type.
   332  //
   333  // Generated from API version 2024-05-01
   334  //   - resourceGroupName - The name of the resource group.
   335  //   - localNetworkGatewayName - The name of the local network gateway.
   336  //   - parameters - Parameters supplied to update local network gateway tags.
   337  //   - options - LocalNetworkGatewaysClientUpdateTagsOptions contains the optional parameters for the LocalNetworkGatewaysClient.UpdateTags
   338  //     method.
   339  func (client *LocalNetworkGatewaysClient) UpdateTags(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, parameters TagsObject, options *LocalNetworkGatewaysClientUpdateTagsOptions) (LocalNetworkGatewaysClientUpdateTagsResponse, error) {
   340  	var err error
   341  	const operationName = "LocalNetworkGatewaysClient.UpdateTags"
   342  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   343  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   344  	defer func() { endSpan(err) }()
   345  	req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, localNetworkGatewayName, parameters, options)
   346  	if err != nil {
   347  		return LocalNetworkGatewaysClientUpdateTagsResponse{}, err
   348  	}
   349  	httpResp, err := client.internal.Pipeline().Do(req)
   350  	if err != nil {
   351  		return LocalNetworkGatewaysClientUpdateTagsResponse{}, err
   352  	}
   353  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
   354  		err = runtime.NewResponseError(httpResp)
   355  		return LocalNetworkGatewaysClientUpdateTagsResponse{}, err
   356  	}
   357  	resp, err := client.updateTagsHandleResponse(httpResp)
   358  	return resp, err
   359  }
   360  
   361  // updateTagsCreateRequest creates the UpdateTags request.
   362  func (client *LocalNetworkGatewaysClient) updateTagsCreateRequest(ctx context.Context, resourceGroupName string, localNetworkGatewayName string, parameters TagsObject, options *LocalNetworkGatewaysClientUpdateTagsOptions) (*policy.Request, error) {
   363  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/localNetworkGateways/{localNetworkGatewayName}"
   364  	if resourceGroupName == "" {
   365  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   366  	}
   367  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   368  	if localNetworkGatewayName == "" {
   369  		return nil, errors.New("parameter localNetworkGatewayName cannot be empty")
   370  	}
   371  	urlPath = strings.ReplaceAll(urlPath, "{localNetworkGatewayName}", url.PathEscape(localNetworkGatewayName))
   372  	if client.subscriptionID == "" {
   373  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   374  	}
   375  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   376  	req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   377  	if err != nil {
   378  		return nil, err
   379  	}
   380  	reqQP := req.Raw().URL.Query()
   381  	reqQP.Set("api-version", "2024-05-01")
   382  	req.Raw().URL.RawQuery = reqQP.Encode()
   383  	req.Raw().Header["Accept"] = []string{"application/json"}
   384  	if err := runtime.MarshalAsJSON(req, parameters); err != nil {
   385  		return nil, err
   386  	}
   387  	return req, nil
   388  }
   389  
   390  // updateTagsHandleResponse handles the UpdateTags response.
   391  func (client *LocalNetworkGatewaysClient) updateTagsHandleResponse(resp *http.Response) (LocalNetworkGatewaysClientUpdateTagsResponse, error) {
   392  	result := LocalNetworkGatewaysClientUpdateTagsResponse{}
   393  	if err := runtime.UnmarshalAsJSON(resp, &result.LocalNetworkGateway); err != nil {
   394  		return LocalNetworkGatewaysClientUpdateTagsResponse{}, err
   395  	}
   396  	return result, nil
   397  }