github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/firewallpolicyrulecollectiongroupdrafts_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  // FirewallPolicyRuleCollectionGroupDraftsServer is a fake server for instances of the armnetwork.FirewallPolicyRuleCollectionGroupDraftsClient type.
    25  type FirewallPolicyRuleCollectionGroupDraftsServer struct {
    26  	// CreateOrUpdate is the fake for method FirewallPolicyRuleCollectionGroupDraftsClient.CreateOrUpdate
    27  	// HTTP status codes to indicate success: http.StatusOK, http.StatusCreated
    28  	CreateOrUpdate func(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleCollectionGroupName string, parameters armnetwork.FirewallPolicyRuleCollectionGroupDraft, options *armnetwork.FirewallPolicyRuleCollectionGroupDraftsClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.FirewallPolicyRuleCollectionGroupDraftsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder)
    29  
    30  	// Delete is the fake for method FirewallPolicyRuleCollectionGroupDraftsClient.Delete
    31  	// HTTP status codes to indicate success: http.StatusOK, http.StatusNoContent
    32  	Delete func(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleCollectionGroupName string, options *armnetwork.FirewallPolicyRuleCollectionGroupDraftsClientDeleteOptions) (resp azfake.Responder[armnetwork.FirewallPolicyRuleCollectionGroupDraftsClientDeleteResponse], errResp azfake.ErrorResponder)
    33  
    34  	// Get is the fake for method FirewallPolicyRuleCollectionGroupDraftsClient.Get
    35  	// HTTP status codes to indicate success: http.StatusOK
    36  	Get func(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleCollectionGroupName string, options *armnetwork.FirewallPolicyRuleCollectionGroupDraftsClientGetOptions) (resp azfake.Responder[armnetwork.FirewallPolicyRuleCollectionGroupDraftsClientGetResponse], errResp azfake.ErrorResponder)
    37  }
    38  
    39  // NewFirewallPolicyRuleCollectionGroupDraftsServerTransport creates a new instance of FirewallPolicyRuleCollectionGroupDraftsServerTransport with the provided implementation.
    40  // The returned FirewallPolicyRuleCollectionGroupDraftsServerTransport instance is connected to an instance of armnetwork.FirewallPolicyRuleCollectionGroupDraftsClient via the
    41  // azcore.ClientOptions.Transporter field in the client's constructor parameters.
    42  func NewFirewallPolicyRuleCollectionGroupDraftsServerTransport(srv *FirewallPolicyRuleCollectionGroupDraftsServer) *FirewallPolicyRuleCollectionGroupDraftsServerTransport {
    43  	return &FirewallPolicyRuleCollectionGroupDraftsServerTransport{srv: srv}
    44  }
    45  
    46  // FirewallPolicyRuleCollectionGroupDraftsServerTransport connects instances of armnetwork.FirewallPolicyRuleCollectionGroupDraftsClient to instances of FirewallPolicyRuleCollectionGroupDraftsServer.
    47  // Don't use this type directly, use NewFirewallPolicyRuleCollectionGroupDraftsServerTransport instead.
    48  type FirewallPolicyRuleCollectionGroupDraftsServerTransport struct {
    49  	srv *FirewallPolicyRuleCollectionGroupDraftsServer
    50  }
    51  
    52  // Do implements the policy.Transporter interface for FirewallPolicyRuleCollectionGroupDraftsServerTransport.
    53  func (f *FirewallPolicyRuleCollectionGroupDraftsServerTransport) Do(req *http.Request) (*http.Response, error) {
    54  	rawMethod := req.Context().Value(runtime.CtxAPINameKey{})
    55  	method, ok := rawMethod.(string)
    56  	if !ok {
    57  		return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")}
    58  	}
    59  
    60  	var resp *http.Response
    61  	var err error
    62  
    63  	switch method {
    64  	case "FirewallPolicyRuleCollectionGroupDraftsClient.CreateOrUpdate":
    65  		resp, err = f.dispatchCreateOrUpdate(req)
    66  	case "FirewallPolicyRuleCollectionGroupDraftsClient.Delete":
    67  		resp, err = f.dispatchDelete(req)
    68  	case "FirewallPolicyRuleCollectionGroupDraftsClient.Get":
    69  		resp, err = f.dispatchGet(req)
    70  	default:
    71  		err = fmt.Errorf("unhandled API %s", method)
    72  	}
    73  
    74  	if err != nil {
    75  		return nil, err
    76  	}
    77  
    78  	return resp, nil
    79  }
    80  
    81  func (f *FirewallPolicyRuleCollectionGroupDraftsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) {
    82  	if f.srv.CreateOrUpdate == nil {
    83  		return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")}
    84  	}
    85  	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~%@]+)/ruleCollectionGroups/(?P<ruleCollectionGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollectionGroupDrafts/default`
    86  	regex := regexp.MustCompile(regexStr)
    87  	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
    88  	if matches == nil || len(matches) < 4 {
    89  		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
    90  	}
    91  	body, err := server.UnmarshalRequestAsJSON[armnetwork.FirewallPolicyRuleCollectionGroupDraft](req)
    92  	if err != nil {
    93  		return nil, err
    94  	}
    95  	resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
    96  	if err != nil {
    97  		return nil, err
    98  	}
    99  	firewallPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")])
   100  	if err != nil {
   101  		return nil, err
   102  	}
   103  	ruleCollectionGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionGroupName")])
   104  	if err != nil {
   105  		return nil, err
   106  	}
   107  	respr, errRespr := f.srv.CreateOrUpdate(req.Context(), resourceGroupNameParam, firewallPolicyNameParam, ruleCollectionGroupNameParam, body, nil)
   108  	if respErr := server.GetError(errRespr, req); respErr != nil {
   109  		return nil, respErr
   110  	}
   111  	respContent := server.GetResponseContent(respr)
   112  	if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) {
   113  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)}
   114  	}
   115  	resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).FirewallPolicyRuleCollectionGroupDraft, req)
   116  	if err != nil {
   117  		return nil, err
   118  	}
   119  	return resp, nil
   120  }
   121  
   122  func (f *FirewallPolicyRuleCollectionGroupDraftsServerTransport) dispatchDelete(req *http.Request) (*http.Response, error) {
   123  	if f.srv.Delete == nil {
   124  		return nil, &nonRetriableError{errors.New("fake for method Delete not implemented")}
   125  	}
   126  	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~%@]+)/ruleCollectionGroups/(?P<ruleCollectionGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollectionGroupDrafts/default`
   127  	regex := regexp.MustCompile(regexStr)
   128  	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   129  	if matches == nil || len(matches) < 4 {
   130  		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   131  	}
   132  	resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   133  	if err != nil {
   134  		return nil, err
   135  	}
   136  	firewallPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")])
   137  	if err != nil {
   138  		return nil, err
   139  	}
   140  	ruleCollectionGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionGroupName")])
   141  	if err != nil {
   142  		return nil, err
   143  	}
   144  	respr, errRespr := f.srv.Delete(req.Context(), resourceGroupNameParam, firewallPolicyNameParam, ruleCollectionGroupNameParam, nil)
   145  	if respErr := server.GetError(errRespr, req); respErr != nil {
   146  		return nil, respErr
   147  	}
   148  	respContent := server.GetResponseContent(respr)
   149  	if !contains([]int{http.StatusOK, http.StatusNoContent}, respContent.HTTPStatus) {
   150  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusNoContent", respContent.HTTPStatus)}
   151  	}
   152  	resp, err := server.NewResponse(respContent, req, nil)
   153  	if err != nil {
   154  		return nil, err
   155  	}
   156  	return resp, nil
   157  }
   158  
   159  func (f *FirewallPolicyRuleCollectionGroupDraftsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) {
   160  	if f.srv.Get == nil {
   161  		return nil, &nonRetriableError{errors.New("fake for method Get not implemented")}
   162  	}
   163  	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~%@]+)/ruleCollectionGroups/(?P<ruleCollectionGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollectionGroupDrafts/default`
   164  	regex := regexp.MustCompile(regexStr)
   165  	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   166  	if matches == nil || len(matches) < 4 {
   167  		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   168  	}
   169  	resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   170  	if err != nil {
   171  		return nil, err
   172  	}
   173  	firewallPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")])
   174  	if err != nil {
   175  		return nil, err
   176  	}
   177  	ruleCollectionGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionGroupName")])
   178  	if err != nil {
   179  		return nil, err
   180  	}
   181  	respr, errRespr := f.srv.Get(req.Context(), resourceGroupNameParam, firewallPolicyNameParam, ruleCollectionGroupNameParam, nil)
   182  	if respErr := server.GetError(errRespr, req); respErr != nil {
   183  		return nil, respErr
   184  	}
   185  	respContent := server.GetResponseContent(respr)
   186  	if !contains([]int{http.StatusOK}, respContent.HTTPStatus) {
   187  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)}
   188  	}
   189  	resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).FirewallPolicyRuleCollectionGroupDraft, req)
   190  	if err != nil {
   191  		return nil, err
   192  	}
   193  	return resp, nil
   194  }