github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/webapplicationfirewallpolicies_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/azcore/to"
    19  	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6"
    20  	"net/http"
    21  	"net/url"
    22  	"regexp"
    23  )
    24  
    25  // WebApplicationFirewallPoliciesServer is a fake server for instances of the armnetwork.WebApplicationFirewallPoliciesClient type.
    26  type WebApplicationFirewallPoliciesServer struct {
    27  	// CreateOrUpdate is the fake for method WebApplicationFirewallPoliciesClient.CreateOrUpdate
    28  	// HTTP status codes to indicate success: http.StatusOK, http.StatusCreated
    29  	CreateOrUpdate func(ctx context.Context, resourceGroupName string, policyName string, parameters armnetwork.WebApplicationFirewallPolicy, options *armnetwork.WebApplicationFirewallPoliciesClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.WebApplicationFirewallPoliciesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder)
    30  
    31  	// BeginDelete is the fake for method WebApplicationFirewallPoliciesClient.BeginDelete
    32  	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
    33  	BeginDelete func(ctx context.Context, resourceGroupName string, policyName string, options *armnetwork.WebApplicationFirewallPoliciesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.WebApplicationFirewallPoliciesClientDeleteResponse], errResp azfake.ErrorResponder)
    34  
    35  	// Get is the fake for method WebApplicationFirewallPoliciesClient.Get
    36  	// HTTP status codes to indicate success: http.StatusOK
    37  	Get func(ctx context.Context, resourceGroupName string, policyName string, options *armnetwork.WebApplicationFirewallPoliciesClientGetOptions) (resp azfake.Responder[armnetwork.WebApplicationFirewallPoliciesClientGetResponse], errResp azfake.ErrorResponder)
    38  
    39  	// NewListPager is the fake for method WebApplicationFirewallPoliciesClient.NewListPager
    40  	// HTTP status codes to indicate success: http.StatusOK
    41  	NewListPager func(resourceGroupName string, options *armnetwork.WebApplicationFirewallPoliciesClientListOptions) (resp azfake.PagerResponder[armnetwork.WebApplicationFirewallPoliciesClientListResponse])
    42  
    43  	// NewListAllPager is the fake for method WebApplicationFirewallPoliciesClient.NewListAllPager
    44  	// HTTP status codes to indicate success: http.StatusOK
    45  	NewListAllPager func(options *armnetwork.WebApplicationFirewallPoliciesClientListAllOptions) (resp azfake.PagerResponder[armnetwork.WebApplicationFirewallPoliciesClientListAllResponse])
    46  }
    47  
    48  // NewWebApplicationFirewallPoliciesServerTransport creates a new instance of WebApplicationFirewallPoliciesServerTransport with the provided implementation.
    49  // The returned WebApplicationFirewallPoliciesServerTransport instance is connected to an instance of armnetwork.WebApplicationFirewallPoliciesClient via the
    50  // azcore.ClientOptions.Transporter field in the client's constructor parameters.
    51  func NewWebApplicationFirewallPoliciesServerTransport(srv *WebApplicationFirewallPoliciesServer) *WebApplicationFirewallPoliciesServerTransport {
    52  	return &WebApplicationFirewallPoliciesServerTransport{
    53  		srv:             srv,
    54  		beginDelete:     newTracker[azfake.PollerResponder[armnetwork.WebApplicationFirewallPoliciesClientDeleteResponse]](),
    55  		newListPager:    newTracker[azfake.PagerResponder[armnetwork.WebApplicationFirewallPoliciesClientListResponse]](),
    56  		newListAllPager: newTracker[azfake.PagerResponder[armnetwork.WebApplicationFirewallPoliciesClientListAllResponse]](),
    57  	}
    58  }
    59  
    60  // WebApplicationFirewallPoliciesServerTransport connects instances of armnetwork.WebApplicationFirewallPoliciesClient to instances of WebApplicationFirewallPoliciesServer.
    61  // Don't use this type directly, use NewWebApplicationFirewallPoliciesServerTransport instead.
    62  type WebApplicationFirewallPoliciesServerTransport struct {
    63  	srv             *WebApplicationFirewallPoliciesServer
    64  	beginDelete     *tracker[azfake.PollerResponder[armnetwork.WebApplicationFirewallPoliciesClientDeleteResponse]]
    65  	newListPager    *tracker[azfake.PagerResponder[armnetwork.WebApplicationFirewallPoliciesClientListResponse]]
    66  	newListAllPager *tracker[azfake.PagerResponder[armnetwork.WebApplicationFirewallPoliciesClientListAllResponse]]
    67  }
    68  
    69  // Do implements the policy.Transporter interface for WebApplicationFirewallPoliciesServerTransport.
    70  func (w *WebApplicationFirewallPoliciesServerTransport) Do(req *http.Request) (*http.Response, error) {
    71  	rawMethod := req.Context().Value(runtime.CtxAPINameKey{})
    72  	method, ok := rawMethod.(string)
    73  	if !ok {
    74  		return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")}
    75  	}
    76  
    77  	var resp *http.Response
    78  	var err error
    79  
    80  	switch method {
    81  	case "WebApplicationFirewallPoliciesClient.CreateOrUpdate":
    82  		resp, err = w.dispatchCreateOrUpdate(req)
    83  	case "WebApplicationFirewallPoliciesClient.BeginDelete":
    84  		resp, err = w.dispatchBeginDelete(req)
    85  	case "WebApplicationFirewallPoliciesClient.Get":
    86  		resp, err = w.dispatchGet(req)
    87  	case "WebApplicationFirewallPoliciesClient.NewListPager":
    88  		resp, err = w.dispatchNewListPager(req)
    89  	case "WebApplicationFirewallPoliciesClient.NewListAllPager":
    90  		resp, err = w.dispatchNewListAllPager(req)
    91  	default:
    92  		err = fmt.Errorf("unhandled API %s", method)
    93  	}
    94  
    95  	if err != nil {
    96  		return nil, err
    97  	}
    98  
    99  	return resp, nil
   100  }
   101  
   102  func (w *WebApplicationFirewallPoliciesServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) {
   103  	if w.srv.CreateOrUpdate == nil {
   104  		return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")}
   105  	}
   106  	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/ApplicationGatewayWebApplicationFirewallPolicies/(?P<policyName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
   107  	regex := regexp.MustCompile(regexStr)
   108  	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   109  	if matches == nil || len(matches) < 3 {
   110  		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   111  	}
   112  	body, err := server.UnmarshalRequestAsJSON[armnetwork.WebApplicationFirewallPolicy](req)
   113  	if err != nil {
   114  		return nil, err
   115  	}
   116  	resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   117  	if err != nil {
   118  		return nil, err
   119  	}
   120  	policyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyName")])
   121  	if err != nil {
   122  		return nil, err
   123  	}
   124  	respr, errRespr := w.srv.CreateOrUpdate(req.Context(), resourceGroupNameParam, policyNameParam, body, nil)
   125  	if respErr := server.GetError(errRespr, req); respErr != nil {
   126  		return nil, respErr
   127  	}
   128  	respContent := server.GetResponseContent(respr)
   129  	if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) {
   130  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)}
   131  	}
   132  	resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).WebApplicationFirewallPolicy, req)
   133  	if err != nil {
   134  		return nil, err
   135  	}
   136  	return resp, nil
   137  }
   138  
   139  func (w *WebApplicationFirewallPoliciesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) {
   140  	if w.srv.BeginDelete == nil {
   141  		return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")}
   142  	}
   143  	beginDelete := w.beginDelete.get(req)
   144  	if beginDelete == nil {
   145  		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/ApplicationGatewayWebApplicationFirewallPolicies/(?P<policyName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
   146  		regex := regexp.MustCompile(regexStr)
   147  		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   148  		if matches == nil || len(matches) < 3 {
   149  			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   150  		}
   151  		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   152  		if err != nil {
   153  			return nil, err
   154  		}
   155  		policyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyName")])
   156  		if err != nil {
   157  			return nil, err
   158  		}
   159  		respr, errRespr := w.srv.BeginDelete(req.Context(), resourceGroupNameParam, policyNameParam, nil)
   160  		if respErr := server.GetError(errRespr, req); respErr != nil {
   161  			return nil, respErr
   162  		}
   163  		beginDelete = &respr
   164  		w.beginDelete.add(req, beginDelete)
   165  	}
   166  
   167  	resp, err := server.PollerResponderNext(beginDelete, req)
   168  	if err != nil {
   169  		return nil, err
   170  	}
   171  
   172  	if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
   173  		w.beginDelete.remove(req)
   174  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)}
   175  	}
   176  	if !server.PollerResponderMore(beginDelete) {
   177  		w.beginDelete.remove(req)
   178  	}
   179  
   180  	return resp, nil
   181  }
   182  
   183  func (w *WebApplicationFirewallPoliciesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) {
   184  	if w.srv.Get == nil {
   185  		return nil, &nonRetriableError{errors.New("fake for method Get not implemented")}
   186  	}
   187  	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/ApplicationGatewayWebApplicationFirewallPolicies/(?P<policyName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
   188  	regex := regexp.MustCompile(regexStr)
   189  	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   190  	if matches == nil || len(matches) < 3 {
   191  		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   192  	}
   193  	resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   194  	if err != nil {
   195  		return nil, err
   196  	}
   197  	policyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("policyName")])
   198  	if err != nil {
   199  		return nil, err
   200  	}
   201  	respr, errRespr := w.srv.Get(req.Context(), resourceGroupNameParam, policyNameParam, nil)
   202  	if respErr := server.GetError(errRespr, req); respErr != nil {
   203  		return nil, respErr
   204  	}
   205  	respContent := server.GetResponseContent(respr)
   206  	if !contains([]int{http.StatusOK}, respContent.HTTPStatus) {
   207  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)}
   208  	}
   209  	resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).WebApplicationFirewallPolicy, req)
   210  	if err != nil {
   211  		return nil, err
   212  	}
   213  	return resp, nil
   214  }
   215  
   216  func (w *WebApplicationFirewallPoliciesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) {
   217  	if w.srv.NewListPager == nil {
   218  		return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")}
   219  	}
   220  	newListPager := w.newListPager.get(req)
   221  	if newListPager == nil {
   222  		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/ApplicationGatewayWebApplicationFirewallPolicies`
   223  		regex := regexp.MustCompile(regexStr)
   224  		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   225  		if matches == nil || len(matches) < 2 {
   226  			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   227  		}
   228  		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   229  		if err != nil {
   230  			return nil, err
   231  		}
   232  		resp := w.srv.NewListPager(resourceGroupNameParam, nil)
   233  		newListPager = &resp
   234  		w.newListPager.add(req, newListPager)
   235  		server.PagerResponderInjectNextLinks(newListPager, req, func(page *armnetwork.WebApplicationFirewallPoliciesClientListResponse, createLink func() string) {
   236  			page.NextLink = to.Ptr(createLink())
   237  		})
   238  	}
   239  	resp, err := server.PagerResponderNext(newListPager, req)
   240  	if err != nil {
   241  		return nil, err
   242  	}
   243  	if !contains([]int{http.StatusOK}, resp.StatusCode) {
   244  		w.newListPager.remove(req)
   245  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
   246  	}
   247  	if !server.PagerResponderMore(newListPager) {
   248  		w.newListPager.remove(req)
   249  	}
   250  	return resp, nil
   251  }
   252  
   253  func (w *WebApplicationFirewallPoliciesServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) {
   254  	if w.srv.NewListAllPager == nil {
   255  		return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")}
   256  	}
   257  	newListAllPager := w.newListAllPager.get(req)
   258  	if newListAllPager == nil {
   259  		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/ApplicationGatewayWebApplicationFirewallPolicies`
   260  		regex := regexp.MustCompile(regexStr)
   261  		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   262  		if matches == nil || len(matches) < 1 {
   263  			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   264  		}
   265  		resp := w.srv.NewListAllPager(nil)
   266  		newListAllPager = &resp
   267  		w.newListAllPager.add(req, newListAllPager)
   268  		server.PagerResponderInjectNextLinks(newListAllPager, req, func(page *armnetwork.WebApplicationFirewallPoliciesClientListAllResponse, createLink func() string) {
   269  			page.NextLink = to.Ptr(createLink())
   270  		})
   271  	}
   272  	resp, err := server.PagerResponderNext(newListAllPager, req)
   273  	if err != nil {
   274  		return nil, err
   275  	}
   276  	if !contains([]int{http.StatusOK}, resp.StatusCode) {
   277  		w.newListAllPager.remove(req)
   278  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
   279  	}
   280  	if !server.PagerResponderMore(newListAllPager) {
   281  		w.newListAllPager.remove(req)
   282  	}
   283  	return resp, nil
   284  }