github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/firewallpolicyidpssignatures_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  // FirewallPolicyIdpsSignaturesClient contains the methods for the FirewallPolicyIdpsSignatures group.
    24  // Don't use this type directly, use NewFirewallPolicyIdpsSignaturesClient() instead.
    25  type FirewallPolicyIdpsSignaturesClient struct {
    26  	internal       *arm.Client
    27  	subscriptionID string
    28  }
    29  
    30  // NewFirewallPolicyIdpsSignaturesClient creates a new instance of FirewallPolicyIdpsSignaturesClient 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 NewFirewallPolicyIdpsSignaturesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*FirewallPolicyIdpsSignaturesClient, error) {
    36  	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	client := &FirewallPolicyIdpsSignaturesClient{
    41  		subscriptionID: subscriptionID,
    42  		internal:       cl,
    43  	}
    44  	return client, nil
    45  }
    46  
    47  // List - Retrieves the current status of IDPS signatures for the relevant policy. Maximal amount of returned signatures is
    48  // 1000.
    49  // If the operation fails it returns an *azcore.ResponseError type.
    50  //
    51  // Generated from API version 2024-05-01
    52  //   - resourceGroupName - The name of the resource group.
    53  //   - firewallPolicyName - The name of the Firewall Policy.
    54  //   - options - FirewallPolicyIdpsSignaturesClientListOptions contains the optional parameters for the FirewallPolicyIdpsSignaturesClient.List
    55  //     method.
    56  func (client *FirewallPolicyIdpsSignaturesClient) List(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters IDPSQueryObject, options *FirewallPolicyIdpsSignaturesClientListOptions) (FirewallPolicyIdpsSignaturesClientListResponse, error) {
    57  	var err error
    58  	const operationName = "FirewallPolicyIdpsSignaturesClient.List"
    59  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
    60  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
    61  	defer func() { endSpan(err) }()
    62  	req, err := client.listCreateRequest(ctx, resourceGroupName, firewallPolicyName, parameters, options)
    63  	if err != nil {
    64  		return FirewallPolicyIdpsSignaturesClientListResponse{}, err
    65  	}
    66  	httpResp, err := client.internal.Pipeline().Do(req)
    67  	if err != nil {
    68  		return FirewallPolicyIdpsSignaturesClientListResponse{}, err
    69  	}
    70  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
    71  		err = runtime.NewResponseError(httpResp)
    72  		return FirewallPolicyIdpsSignaturesClientListResponse{}, err
    73  	}
    74  	resp, err := client.listHandleResponse(httpResp)
    75  	return resp, err
    76  }
    77  
    78  // listCreateRequest creates the List request.
    79  func (client *FirewallPolicyIdpsSignaturesClient) listCreateRequest(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters IDPSQueryObject, options *FirewallPolicyIdpsSignaturesClientListOptions) (*policy.Request, error) {
    80  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/firewallPolicies/{firewallPolicyName}/listIdpsSignatures"
    81  	if resourceGroupName == "" {
    82  		return nil, errors.New("parameter resourceGroupName cannot be empty")
    83  	}
    84  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
    85  	if firewallPolicyName == "" {
    86  		return nil, errors.New("parameter firewallPolicyName cannot be empty")
    87  	}
    88  	urlPath = strings.ReplaceAll(urlPath, "{firewallPolicyName}", url.PathEscape(firewallPolicyName))
    89  	if client.subscriptionID == "" {
    90  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
    91  	}
    92  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
    93  	req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
    94  	if err != nil {
    95  		return nil, err
    96  	}
    97  	reqQP := req.Raw().URL.Query()
    98  	reqQP.Set("api-version", "2024-05-01")
    99  	req.Raw().URL.RawQuery = reqQP.Encode()
   100  	req.Raw().Header["Accept"] = []string{"application/json"}
   101  	if err := runtime.MarshalAsJSON(req, parameters); err != nil {
   102  		return nil, err
   103  	}
   104  	return req, nil
   105  }
   106  
   107  // listHandleResponse handles the List response.
   108  func (client *FirewallPolicyIdpsSignaturesClient) listHandleResponse(resp *http.Response) (FirewallPolicyIdpsSignaturesClientListResponse, error) {
   109  	result := FirewallPolicyIdpsSignaturesClientListResponse{}
   110  	if err := runtime.UnmarshalAsJSON(resp, &result.QueryResults); err != nil {
   111  		return FirewallPolicyIdpsSignaturesClientListResponse{}, err
   112  	}
   113  	return result, nil
   114  }