1package cdn 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/tracing" 25 "net/http" 26) 27 28// ManagedRuleSetsClient is the cdn Management Client 29type ManagedRuleSetsClient struct { 30 BaseClient 31} 32 33// NewManagedRuleSetsClient creates an instance of the ManagedRuleSetsClient client. 34func NewManagedRuleSetsClient(subscriptionID string, subscriptionID1 string) ManagedRuleSetsClient { 35 return NewManagedRuleSetsClientWithBaseURI(DefaultBaseURI, subscriptionID, subscriptionID1) 36} 37 38// NewManagedRuleSetsClientWithBaseURI creates an instance of the ManagedRuleSetsClient client using a custom endpoint. 39// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 40func NewManagedRuleSetsClientWithBaseURI(baseURI string, subscriptionID string, subscriptionID1 string) ManagedRuleSetsClient { 41 return ManagedRuleSetsClient{NewWithBaseURI(baseURI, subscriptionID, subscriptionID1)} 42} 43 44// List lists all available managed rule sets. 45func (client ManagedRuleSetsClient) List(ctx context.Context) (result ManagedRuleSetDefinitionListPage, err error) { 46 if tracing.IsEnabled() { 47 ctx = tracing.StartSpan(ctx, fqdn+"/ManagedRuleSetsClient.List") 48 defer func() { 49 sc := -1 50 if result.mrsdl.Response.Response != nil { 51 sc = result.mrsdl.Response.Response.StatusCode 52 } 53 tracing.EndSpan(ctx, sc, err) 54 }() 55 } 56 result.fn = client.listNextResults 57 req, err := client.ListPreparer(ctx) 58 if err != nil { 59 err = autorest.NewErrorWithError(err, "cdn.ManagedRuleSetsClient", "List", nil, "Failure preparing request") 60 return 61 } 62 63 resp, err := client.ListSender(req) 64 if err != nil { 65 result.mrsdl.Response = autorest.Response{Response: resp} 66 err = autorest.NewErrorWithError(err, "cdn.ManagedRuleSetsClient", "List", resp, "Failure sending request") 67 return 68 } 69 70 result.mrsdl, err = client.ListResponder(resp) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "cdn.ManagedRuleSetsClient", "List", resp, "Failure responding to request") 73 } 74 75 return 76} 77 78// ListPreparer prepares the List request. 79func (client ManagedRuleSetsClient) ListPreparer(ctx context.Context) (*http.Request, error) { 80 pathParameters := map[string]interface{}{ 81 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 82 } 83 84 const APIVersion = "2019-06-15" 85 queryParameters := map[string]interface{}{ 86 "api-version": APIVersion, 87 } 88 89 preparer := autorest.CreatePreparer( 90 autorest.AsGet(), 91 autorest.WithBaseURL(client.BaseURI), 92 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Cdn/CdnWebApplicationFirewallManagedRuleSets", pathParameters), 93 autorest.WithQueryParameters(queryParameters)) 94 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 95} 96 97// ListSender sends the List request. The method will close the 98// http.Response Body if it receives an error. 99func (client ManagedRuleSetsClient) ListSender(req *http.Request) (*http.Response, error) { 100 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 101} 102 103// ListResponder handles the response to the List request. The method always 104// closes the http.Response Body. 105func (client ManagedRuleSetsClient) ListResponder(resp *http.Response) (result ManagedRuleSetDefinitionList, err error) { 106 err = autorest.Respond( 107 resp, 108 client.ByInspecting(), 109 azure.WithErrorUnlessStatusCode(http.StatusOK), 110 autorest.ByUnmarshallingJSON(&result), 111 autorest.ByClosing()) 112 result.Response = autorest.Response{Response: resp} 113 return 114} 115 116// listNextResults retrieves the next set of results, if any. 117func (client ManagedRuleSetsClient) listNextResults(ctx context.Context, lastResults ManagedRuleSetDefinitionList) (result ManagedRuleSetDefinitionList, err error) { 118 req, err := lastResults.managedRuleSetDefinitionListPreparer(ctx) 119 if err != nil { 120 return result, autorest.NewErrorWithError(err, "cdn.ManagedRuleSetsClient", "listNextResults", nil, "Failure preparing next results request") 121 } 122 if req == nil { 123 return 124 } 125 resp, err := client.ListSender(req) 126 if err != nil { 127 result.Response = autorest.Response{Response: resp} 128 return result, autorest.NewErrorWithError(err, "cdn.ManagedRuleSetsClient", "listNextResults", resp, "Failure sending next results request") 129 } 130 result, err = client.ListResponder(resp) 131 if err != nil { 132 err = autorest.NewErrorWithError(err, "cdn.ManagedRuleSetsClient", "listNextResults", resp, "Failure responding to next results request") 133 } 134 return 135} 136 137// ListComplete enumerates all values, automatically crossing page boundaries as required. 138func (client ManagedRuleSetsClient) ListComplete(ctx context.Context) (result ManagedRuleSetDefinitionListIterator, err error) { 139 if tracing.IsEnabled() { 140 ctx = tracing.StartSpan(ctx, fqdn+"/ManagedRuleSetsClient.List") 141 defer func() { 142 sc := -1 143 if result.Response().Response.Response != nil { 144 sc = result.page.Response().Response.Response.StatusCode 145 } 146 tracing.EndSpan(ctx, sc, err) 147 }() 148 } 149 result.page, err = client.List(ctx) 150 return 151} 152