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