github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/applicationgatewaywafdynamicmanifests_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  // ApplicationGatewayWafDynamicManifestsClient contains the methods for the ApplicationGatewayWafDynamicManifests group.
    24  // Don't use this type directly, use NewApplicationGatewayWafDynamicManifestsClient() instead.
    25  type ApplicationGatewayWafDynamicManifestsClient struct {
    26  	internal       *arm.Client
    27  	subscriptionID string
    28  }
    29  
    30  // NewApplicationGatewayWafDynamicManifestsClient creates a new instance of ApplicationGatewayWafDynamicManifestsClient 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 NewApplicationGatewayWafDynamicManifestsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ApplicationGatewayWafDynamicManifestsClient, error) {
    36  	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	client := &ApplicationGatewayWafDynamicManifestsClient{
    41  		subscriptionID: subscriptionID,
    42  		internal:       cl,
    43  	}
    44  	return client, nil
    45  }
    46  
    47  // NewGetPager - Gets the regional application gateway waf manifest.
    48  //
    49  // Generated from API version 2024-05-01
    50  //   - location - The region where the nrp are located at.
    51  //   - options - ApplicationGatewayWafDynamicManifestsClientGetOptions contains the optional parameters for the ApplicationGatewayWafDynamicManifestsClient.NewGetPager
    52  //     method.
    53  func (client *ApplicationGatewayWafDynamicManifestsClient) NewGetPager(location string, options *ApplicationGatewayWafDynamicManifestsClientGetOptions) *runtime.Pager[ApplicationGatewayWafDynamicManifestsClientGetResponse] {
    54  	return runtime.NewPager(runtime.PagingHandler[ApplicationGatewayWafDynamicManifestsClientGetResponse]{
    55  		More: func(page ApplicationGatewayWafDynamicManifestsClientGetResponse) bool {
    56  			return page.NextLink != nil && len(*page.NextLink) > 0
    57  		},
    58  		Fetcher: func(ctx context.Context, page *ApplicationGatewayWafDynamicManifestsClientGetResponse) (ApplicationGatewayWafDynamicManifestsClientGetResponse, error) {
    59  			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ApplicationGatewayWafDynamicManifestsClient.NewGetPager")
    60  			nextLink := ""
    61  			if page != nil {
    62  				nextLink = *page.NextLink
    63  			}
    64  			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
    65  				return client.getCreateRequest(ctx, location, options)
    66  			}, nil)
    67  			if err != nil {
    68  				return ApplicationGatewayWafDynamicManifestsClientGetResponse{}, err
    69  			}
    70  			return client.getHandleResponse(resp)
    71  		},
    72  		Tracer: client.internal.Tracer(),
    73  	})
    74  }
    75  
    76  // getCreateRequest creates the Get request.
    77  func (client *ApplicationGatewayWafDynamicManifestsClient) getCreateRequest(ctx context.Context, location string, options *ApplicationGatewayWafDynamicManifestsClientGetOptions) (*policy.Request, error) {
    78  	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/applicationGatewayWafDynamicManifests"
    79  	if location == "" {
    80  		return nil, errors.New("parameter location cannot be empty")
    81  	}
    82  	urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location))
    83  	if client.subscriptionID == "" {
    84  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
    85  	}
    86  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
    87  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
    88  	if err != nil {
    89  		return nil, err
    90  	}
    91  	reqQP := req.Raw().URL.Query()
    92  	reqQP.Set("api-version", "2024-05-01")
    93  	req.Raw().URL.RawQuery = reqQP.Encode()
    94  	req.Raw().Header["Accept"] = []string{"application/json"}
    95  	return req, nil
    96  }
    97  
    98  // getHandleResponse handles the Get response.
    99  func (client *ApplicationGatewayWafDynamicManifestsClient) getHandleResponse(resp *http.Response) (ApplicationGatewayWafDynamicManifestsClientGetResponse, error) {
   100  	result := ApplicationGatewayWafDynamicManifestsClientGetResponse{}
   101  	if err := runtime.UnmarshalAsJSON(resp, &result.ApplicationGatewayWafDynamicManifestResultList); err != nil {
   102  		return ApplicationGatewayWafDynamicManifestsClientGetResponse{}, err
   103  	}
   104  	return result, nil
   105  }