github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/applicationsecuritygroups_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 // ApplicationSecurityGroupsServer is a fake server for instances of the armnetwork.ApplicationSecurityGroupsClient type. 26 type ApplicationSecurityGroupsServer struct { 27 // BeginCreateOrUpdate is the fake for method ApplicationSecurityGroupsClient.BeginCreateOrUpdate 28 // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated 29 BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, applicationSecurityGroupName string, parameters armnetwork.ApplicationSecurityGroup, options *armnetwork.ApplicationSecurityGroupsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ApplicationSecurityGroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) 30 31 // BeginDelete is the fake for method ApplicationSecurityGroupsClient.BeginDelete 32 // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent 33 BeginDelete func(ctx context.Context, resourceGroupName string, applicationSecurityGroupName string, options *armnetwork.ApplicationSecurityGroupsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ApplicationSecurityGroupsClientDeleteResponse], errResp azfake.ErrorResponder) 34 35 // Get is the fake for method ApplicationSecurityGroupsClient.Get 36 // HTTP status codes to indicate success: http.StatusOK 37 Get func(ctx context.Context, resourceGroupName string, applicationSecurityGroupName string, options *armnetwork.ApplicationSecurityGroupsClientGetOptions) (resp azfake.Responder[armnetwork.ApplicationSecurityGroupsClientGetResponse], errResp azfake.ErrorResponder) 38 39 // NewListPager is the fake for method ApplicationSecurityGroupsClient.NewListPager 40 // HTTP status codes to indicate success: http.StatusOK 41 NewListPager func(resourceGroupName string, options *armnetwork.ApplicationSecurityGroupsClientListOptions) (resp azfake.PagerResponder[armnetwork.ApplicationSecurityGroupsClientListResponse]) 42 43 // NewListAllPager is the fake for method ApplicationSecurityGroupsClient.NewListAllPager 44 // HTTP status codes to indicate success: http.StatusOK 45 NewListAllPager func(options *armnetwork.ApplicationSecurityGroupsClientListAllOptions) (resp azfake.PagerResponder[armnetwork.ApplicationSecurityGroupsClientListAllResponse]) 46 47 // UpdateTags is the fake for method ApplicationSecurityGroupsClient.UpdateTags 48 // HTTP status codes to indicate success: http.StatusOK 49 UpdateTags func(ctx context.Context, resourceGroupName string, applicationSecurityGroupName string, parameters armnetwork.TagsObject, options *armnetwork.ApplicationSecurityGroupsClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.ApplicationSecurityGroupsClientUpdateTagsResponse], errResp azfake.ErrorResponder) 50 } 51 52 // NewApplicationSecurityGroupsServerTransport creates a new instance of ApplicationSecurityGroupsServerTransport with the provided implementation. 53 // The returned ApplicationSecurityGroupsServerTransport instance is connected to an instance of armnetwork.ApplicationSecurityGroupsClient via the 54 // azcore.ClientOptions.Transporter field in the client's constructor parameters. 55 func NewApplicationSecurityGroupsServerTransport(srv *ApplicationSecurityGroupsServer) *ApplicationSecurityGroupsServerTransport { 56 return &ApplicationSecurityGroupsServerTransport{ 57 srv: srv, 58 beginCreateOrUpdate: newTracker[azfake.PollerResponder[armnetwork.ApplicationSecurityGroupsClientCreateOrUpdateResponse]](), 59 beginDelete: newTracker[azfake.PollerResponder[armnetwork.ApplicationSecurityGroupsClientDeleteResponse]](), 60 newListPager: newTracker[azfake.PagerResponder[armnetwork.ApplicationSecurityGroupsClientListResponse]](), 61 newListAllPager: newTracker[azfake.PagerResponder[armnetwork.ApplicationSecurityGroupsClientListAllResponse]](), 62 } 63 } 64 65 // ApplicationSecurityGroupsServerTransport connects instances of armnetwork.ApplicationSecurityGroupsClient to instances of ApplicationSecurityGroupsServer. 66 // Don't use this type directly, use NewApplicationSecurityGroupsServerTransport instead. 67 type ApplicationSecurityGroupsServerTransport struct { 68 srv *ApplicationSecurityGroupsServer 69 beginCreateOrUpdate *tracker[azfake.PollerResponder[armnetwork.ApplicationSecurityGroupsClientCreateOrUpdateResponse]] 70 beginDelete *tracker[azfake.PollerResponder[armnetwork.ApplicationSecurityGroupsClientDeleteResponse]] 71 newListPager *tracker[azfake.PagerResponder[armnetwork.ApplicationSecurityGroupsClientListResponse]] 72 newListAllPager *tracker[azfake.PagerResponder[armnetwork.ApplicationSecurityGroupsClientListAllResponse]] 73 } 74 75 // Do implements the policy.Transporter interface for ApplicationSecurityGroupsServerTransport. 76 func (a *ApplicationSecurityGroupsServerTransport) 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 "ApplicationSecurityGroupsClient.BeginCreateOrUpdate": 88 resp, err = a.dispatchBeginCreateOrUpdate(req) 89 case "ApplicationSecurityGroupsClient.BeginDelete": 90 resp, err = a.dispatchBeginDelete(req) 91 case "ApplicationSecurityGroupsClient.Get": 92 resp, err = a.dispatchGet(req) 93 case "ApplicationSecurityGroupsClient.NewListPager": 94 resp, err = a.dispatchNewListPager(req) 95 case "ApplicationSecurityGroupsClient.NewListAllPager": 96 resp, err = a.dispatchNewListAllPager(req) 97 case "ApplicationSecurityGroupsClient.UpdateTags": 98 resp, err = a.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 (a *ApplicationSecurityGroupsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { 111 if a.srv.BeginCreateOrUpdate == nil { 112 return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} 113 } 114 beginCreateOrUpdate := a.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/applicationSecurityGroups/(?P<applicationSecurityGroupName>[!#&$-;=?-\[\]_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.ApplicationSecurityGroup](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 applicationSecurityGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationSecurityGroupName")]) 131 if err != nil { 132 return nil, err 133 } 134 respr, errRespr := a.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, applicationSecurityGroupNameParam, body, nil) 135 if respErr := server.GetError(errRespr, req); respErr != nil { 136 return nil, respErr 137 } 138 beginCreateOrUpdate = &respr 139 a.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 a.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 a.beginCreateOrUpdate.remove(req) 153 } 154 155 return resp, nil 156 } 157 158 func (a *ApplicationSecurityGroupsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { 159 if a.srv.BeginDelete == nil { 160 return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} 161 } 162 beginDelete := a.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/applicationSecurityGroups/(?P<applicationSecurityGroupName>[!#&$-;=?-\[\]_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 applicationSecurityGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationSecurityGroupName")]) 175 if err != nil { 176 return nil, err 177 } 178 respr, errRespr := a.srv.BeginDelete(req.Context(), resourceGroupNameParam, applicationSecurityGroupNameParam, nil) 179 if respErr := server.GetError(errRespr, req); respErr != nil { 180 return nil, respErr 181 } 182 beginDelete = &respr 183 a.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 a.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 a.beginDelete.remove(req) 197 } 198 199 return resp, nil 200 } 201 202 func (a *ApplicationSecurityGroupsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { 203 if a.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/applicationSecurityGroups/(?P<applicationSecurityGroupName>[!#&$-;=?-\[\]_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 applicationSecurityGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationSecurityGroupName")]) 217 if err != nil { 218 return nil, err 219 } 220 respr, errRespr := a.srv.Get(req.Context(), resourceGroupNameParam, applicationSecurityGroupNameParam, 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).ApplicationSecurityGroup, req) 229 if err != nil { 230 return nil, err 231 } 232 return resp, nil 233 } 234 235 func (a *ApplicationSecurityGroupsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { 236 if a.srv.NewListPager == nil { 237 return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} 238 } 239 newListPager := a.newListPager.get(req) 240 if newListPager == nil { 241 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/applicationSecurityGroups` 242 regex := regexp.MustCompile(regexStr) 243 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 244 if matches == nil || len(matches) < 2 { 245 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 246 } 247 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 248 if err != nil { 249 return nil, err 250 } 251 resp := a.srv.NewListPager(resourceGroupNameParam, nil) 252 newListPager = &resp 253 a.newListPager.add(req, newListPager) 254 server.PagerResponderInjectNextLinks(newListPager, req, func(page *armnetwork.ApplicationSecurityGroupsClientListResponse, createLink func() string) { 255 page.NextLink = to.Ptr(createLink()) 256 }) 257 } 258 resp, err := server.PagerResponderNext(newListPager, req) 259 if err != nil { 260 return nil, err 261 } 262 if !contains([]int{http.StatusOK}, resp.StatusCode) { 263 a.newListPager.remove(req) 264 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} 265 } 266 if !server.PagerResponderMore(newListPager) { 267 a.newListPager.remove(req) 268 } 269 return resp, nil 270 } 271 272 func (a *ApplicationSecurityGroupsServerTransport) dispatchNewListAllPager(req *http.Request) (*http.Response, error) { 273 if a.srv.NewListAllPager == nil { 274 return nil, &nonRetriableError{errors.New("fake for method NewListAllPager not implemented")} 275 } 276 newListAllPager := a.newListAllPager.get(req) 277 if newListAllPager == nil { 278 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/applicationSecurityGroups` 279 regex := regexp.MustCompile(regexStr) 280 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 281 if matches == nil || len(matches) < 1 { 282 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 283 } 284 resp := a.srv.NewListAllPager(nil) 285 newListAllPager = &resp 286 a.newListAllPager.add(req, newListAllPager) 287 server.PagerResponderInjectNextLinks(newListAllPager, req, func(page *armnetwork.ApplicationSecurityGroupsClientListAllResponse, createLink func() string) { 288 page.NextLink = to.Ptr(createLink()) 289 }) 290 } 291 resp, err := server.PagerResponderNext(newListAllPager, req) 292 if err != nil { 293 return nil, err 294 } 295 if !contains([]int{http.StatusOK}, resp.StatusCode) { 296 a.newListAllPager.remove(req) 297 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} 298 } 299 if !server.PagerResponderMore(newListAllPager) { 300 a.newListAllPager.remove(req) 301 } 302 return resp, nil 303 } 304 305 func (a *ApplicationSecurityGroupsServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { 306 if a.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/applicationSecurityGroups/(?P<applicationSecurityGroupName>[!#&$-;=?-\[\]_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 applicationSecurityGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("applicationSecurityGroupName")]) 324 if err != nil { 325 return nil, err 326 } 327 respr, errRespr := a.srv.UpdateTags(req.Context(), resourceGroupNameParam, applicationSecurityGroupNameParam, 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).ApplicationSecurityGroup, req) 336 if err != nil { 337 return nil, err 338 } 339 return resp, nil 340 }