github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/firewallpolicyidpssignatures_server.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 fake
    10  
    11  import (
    12  	"context"
    13  	"errors"
    14  	"fmt"
    15  	azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake"
    16  	"github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server"
    17  	"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
    18  	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6"
    19  	"net/http"
    20  	"net/url"
    21  	"regexp"
    22  )
    23  
    24  // FirewallPolicyIdpsSignaturesServer is a fake server for instances of the armnetwork.FirewallPolicyIdpsSignaturesClient type.
    25  type FirewallPolicyIdpsSignaturesServer struct {
    26  	// List is the fake for method FirewallPolicyIdpsSignaturesClient.List
    27  	// HTTP status codes to indicate success: http.StatusOK
    28  	List func(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters armnetwork.IDPSQueryObject, options *armnetwork.FirewallPolicyIdpsSignaturesClientListOptions) (resp azfake.Responder[armnetwork.FirewallPolicyIdpsSignaturesClientListResponse], errResp azfake.ErrorResponder)
    29  }
    30  
    31  // NewFirewallPolicyIdpsSignaturesServerTransport creates a new instance of FirewallPolicyIdpsSignaturesServerTransport with the provided implementation.
    32  // The returned FirewallPolicyIdpsSignaturesServerTransport instance is connected to an instance of armnetwork.FirewallPolicyIdpsSignaturesClient via the
    33  // azcore.ClientOptions.Transporter field in the client's constructor parameters.
    34  func NewFirewallPolicyIdpsSignaturesServerTransport(srv *FirewallPolicyIdpsSignaturesServer) *FirewallPolicyIdpsSignaturesServerTransport {
    35  	return &FirewallPolicyIdpsSignaturesServerTransport{srv: srv}
    36  }
    37  
    38  // FirewallPolicyIdpsSignaturesServerTransport connects instances of armnetwork.FirewallPolicyIdpsSignaturesClient to instances of FirewallPolicyIdpsSignaturesServer.
    39  // Don't use this type directly, use NewFirewallPolicyIdpsSignaturesServerTransport instead.
    40  type FirewallPolicyIdpsSignaturesServerTransport struct {
    41  	srv *FirewallPolicyIdpsSignaturesServer
    42  }
    43  
    44  // Do implements the policy.Transporter interface for FirewallPolicyIdpsSignaturesServerTransport.
    45  func (f *FirewallPolicyIdpsSignaturesServerTransport) Do(req *http.Request) (*http.Response, error) {
    46  	rawMethod := req.Context().Value(runtime.CtxAPINameKey{})
    47  	method, ok := rawMethod.(string)
    48  	if !ok {
    49  		return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")}
    50  	}
    51  
    52  	var resp *http.Response
    53  	var err error
    54  
    55  	switch method {
    56  	case "FirewallPolicyIdpsSignaturesClient.List":
    57  		resp, err = f.dispatchList(req)
    58  	default:
    59  		err = fmt.Errorf("unhandled API %s", method)
    60  	}
    61  
    62  	if err != nil {
    63  		return nil, err
    64  	}
    65  
    66  	return resp, nil
    67  }
    68  
    69  func (f *FirewallPolicyIdpsSignaturesServerTransport) dispatchList(req *http.Request) (*http.Response, error) {
    70  	if f.srv.List == nil {
    71  		return nil, &nonRetriableError{errors.New("fake for method List not implemented")}
    72  	}
    73  	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/firewallPolicies/(?P<firewallPolicyName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/listIdpsSignatures`
    74  	regex := regexp.MustCompile(regexStr)
    75  	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
    76  	if matches == nil || len(matches) < 3 {
    77  		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
    78  	}
    79  	body, err := server.UnmarshalRequestAsJSON[armnetwork.IDPSQueryObject](req)
    80  	if err != nil {
    81  		return nil, err
    82  	}
    83  	resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
    84  	if err != nil {
    85  		return nil, err
    86  	}
    87  	firewallPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")])
    88  	if err != nil {
    89  		return nil, err
    90  	}
    91  	respr, errRespr := f.srv.List(req.Context(), resourceGroupNameParam, firewallPolicyNameParam, body, nil)
    92  	if respErr := server.GetError(errRespr, req); respErr != nil {
    93  		return nil, respErr
    94  	}
    95  	respContent := server.GetResponseContent(respr)
    96  	if !contains([]int{http.StatusOK}, respContent.HTTPStatus) {
    97  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)}
    98  	}
    99  	resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).QueryResults, req)
   100  	if err != nil {
   101  		return nil, err
   102  	}
   103  	return resp, nil
   104  }