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