github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/ddoscustompolicies_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/resourcemanager/network/armnetwork/v6" 19 "net/http" 20 "net/url" 21 "regexp" 22 ) 23 24 // DdosCustomPoliciesServer is a fake server for instances of the armnetwork.DdosCustomPoliciesClient type. 25 type DdosCustomPoliciesServer struct { 26 // BeginCreateOrUpdate is the fake for method DdosCustomPoliciesClient.BeginCreateOrUpdate 27 // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated 28 BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, parameters armnetwork.DdosCustomPolicy, options *armnetwork.DdosCustomPoliciesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.DdosCustomPoliciesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) 29 30 // BeginDelete is the fake for method DdosCustomPoliciesClient.BeginDelete 31 // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent 32 BeginDelete func(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, options *armnetwork.DdosCustomPoliciesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.DdosCustomPoliciesClientDeleteResponse], errResp azfake.ErrorResponder) 33 34 // Get is the fake for method DdosCustomPoliciesClient.Get 35 // HTTP status codes to indicate success: http.StatusOK 36 Get func(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, options *armnetwork.DdosCustomPoliciesClientGetOptions) (resp azfake.Responder[armnetwork.DdosCustomPoliciesClientGetResponse], errResp azfake.ErrorResponder) 37 38 // UpdateTags is the fake for method DdosCustomPoliciesClient.UpdateTags 39 // HTTP status codes to indicate success: http.StatusOK 40 UpdateTags func(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, parameters armnetwork.TagsObject, options *armnetwork.DdosCustomPoliciesClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.DdosCustomPoliciesClientUpdateTagsResponse], errResp azfake.ErrorResponder) 41 } 42 43 // NewDdosCustomPoliciesServerTransport creates a new instance of DdosCustomPoliciesServerTransport with the provided implementation. 44 // The returned DdosCustomPoliciesServerTransport instance is connected to an instance of armnetwork.DdosCustomPoliciesClient via the 45 // azcore.ClientOptions.Transporter field in the client's constructor parameters. 46 func NewDdosCustomPoliciesServerTransport(srv *DdosCustomPoliciesServer) *DdosCustomPoliciesServerTransport { 47 return &DdosCustomPoliciesServerTransport{ 48 srv: srv, 49 beginCreateOrUpdate: newTracker[azfake.PollerResponder[armnetwork.DdosCustomPoliciesClientCreateOrUpdateResponse]](), 50 beginDelete: newTracker[azfake.PollerResponder[armnetwork.DdosCustomPoliciesClientDeleteResponse]](), 51 } 52 } 53 54 // DdosCustomPoliciesServerTransport connects instances of armnetwork.DdosCustomPoliciesClient to instances of DdosCustomPoliciesServer. 55 // Don't use this type directly, use NewDdosCustomPoliciesServerTransport instead. 56 type DdosCustomPoliciesServerTransport struct { 57 srv *DdosCustomPoliciesServer 58 beginCreateOrUpdate *tracker[azfake.PollerResponder[armnetwork.DdosCustomPoliciesClientCreateOrUpdateResponse]] 59 beginDelete *tracker[azfake.PollerResponder[armnetwork.DdosCustomPoliciesClientDeleteResponse]] 60 } 61 62 // Do implements the policy.Transporter interface for DdosCustomPoliciesServerTransport. 63 func (d *DdosCustomPoliciesServerTransport) Do(req *http.Request) (*http.Response, error) { 64 rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) 65 method, ok := rawMethod.(string) 66 if !ok { 67 return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} 68 } 69 70 var resp *http.Response 71 var err error 72 73 switch method { 74 case "DdosCustomPoliciesClient.BeginCreateOrUpdate": 75 resp, err = d.dispatchBeginCreateOrUpdate(req) 76 case "DdosCustomPoliciesClient.BeginDelete": 77 resp, err = d.dispatchBeginDelete(req) 78 case "DdosCustomPoliciesClient.Get": 79 resp, err = d.dispatchGet(req) 80 case "DdosCustomPoliciesClient.UpdateTags": 81 resp, err = d.dispatchUpdateTags(req) 82 default: 83 err = fmt.Errorf("unhandled API %s", method) 84 } 85 86 if err != nil { 87 return nil, err 88 } 89 90 return resp, nil 91 } 92 93 func (d *DdosCustomPoliciesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { 94 if d.srv.BeginCreateOrUpdate == nil { 95 return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} 96 } 97 beginCreateOrUpdate := d.beginCreateOrUpdate.get(req) 98 if beginCreateOrUpdate == nil { 99 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/ddosCustomPolicies/(?P<ddosCustomPolicyName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 100 regex := regexp.MustCompile(regexStr) 101 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 102 if matches == nil || len(matches) < 3 { 103 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 104 } 105 body, err := server.UnmarshalRequestAsJSON[armnetwork.DdosCustomPolicy](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 ddosCustomPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("ddosCustomPolicyName")]) 114 if err != nil { 115 return nil, err 116 } 117 respr, errRespr := d.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, ddosCustomPolicyNameParam, body, nil) 118 if respErr := server.GetError(errRespr, req); respErr != nil { 119 return nil, respErr 120 } 121 beginCreateOrUpdate = &respr 122 d.beginCreateOrUpdate.add(req, beginCreateOrUpdate) 123 } 124 125 resp, err := server.PollerResponderNext(beginCreateOrUpdate, req) 126 if err != nil { 127 return nil, err 128 } 129 130 if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { 131 d.beginCreateOrUpdate.remove(req) 132 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} 133 } 134 if !server.PollerResponderMore(beginCreateOrUpdate) { 135 d.beginCreateOrUpdate.remove(req) 136 } 137 138 return resp, nil 139 } 140 141 func (d *DdosCustomPoliciesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { 142 if d.srv.BeginDelete == nil { 143 return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} 144 } 145 beginDelete := d.beginDelete.get(req) 146 if beginDelete == nil { 147 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/ddosCustomPolicies/(?P<ddosCustomPolicyName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 148 regex := regexp.MustCompile(regexStr) 149 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 150 if matches == nil || len(matches) < 3 { 151 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 152 } 153 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 154 if err != nil { 155 return nil, err 156 } 157 ddosCustomPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("ddosCustomPolicyName")]) 158 if err != nil { 159 return nil, err 160 } 161 respr, errRespr := d.srv.BeginDelete(req.Context(), resourceGroupNameParam, ddosCustomPolicyNameParam, nil) 162 if respErr := server.GetError(errRespr, req); respErr != nil { 163 return nil, respErr 164 } 165 beginDelete = &respr 166 d.beginDelete.add(req, beginDelete) 167 } 168 169 resp, err := server.PollerResponderNext(beginDelete, req) 170 if err != nil { 171 return nil, err 172 } 173 174 if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { 175 d.beginDelete.remove(req) 176 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} 177 } 178 if !server.PollerResponderMore(beginDelete) { 179 d.beginDelete.remove(req) 180 } 181 182 return resp, nil 183 } 184 185 func (d *DdosCustomPoliciesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { 186 if d.srv.Get == nil { 187 return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} 188 } 189 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/ddosCustomPolicies/(?P<ddosCustomPolicyName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 190 regex := regexp.MustCompile(regexStr) 191 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 192 if matches == nil || len(matches) < 3 { 193 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 194 } 195 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 196 if err != nil { 197 return nil, err 198 } 199 ddosCustomPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("ddosCustomPolicyName")]) 200 if err != nil { 201 return nil, err 202 } 203 respr, errRespr := d.srv.Get(req.Context(), resourceGroupNameParam, ddosCustomPolicyNameParam, nil) 204 if respErr := server.GetError(errRespr, req); respErr != nil { 205 return nil, respErr 206 } 207 respContent := server.GetResponseContent(respr) 208 if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { 209 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} 210 } 211 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DdosCustomPolicy, req) 212 if err != nil { 213 return nil, err 214 } 215 return resp, nil 216 } 217 218 func (d *DdosCustomPoliciesServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { 219 if d.srv.UpdateTags == nil { 220 return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} 221 } 222 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/ddosCustomPolicies/(?P<ddosCustomPolicyName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 223 regex := regexp.MustCompile(regexStr) 224 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 225 if matches == nil || len(matches) < 3 { 226 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 227 } 228 body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) 229 if err != nil { 230 return nil, err 231 } 232 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 233 if err != nil { 234 return nil, err 235 } 236 ddosCustomPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("ddosCustomPolicyName")]) 237 if err != nil { 238 return nil, err 239 } 240 respr, errRespr := d.srv.UpdateTags(req.Context(), resourceGroupNameParam, ddosCustomPolicyNameParam, body, nil) 241 if respErr := server.GetError(errRespr, req); respErr != nil { 242 return nil, respErr 243 } 244 respContent := server.GetResponseContent(respr) 245 if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { 246 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} 247 } 248 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).DdosCustomPolicy, req) 249 if err != nil { 250 return nil, err 251 } 252 return resp, nil 253 }