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