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