1package apimanagement 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/autorest/validation" 25 "net/http" 26) 27 28// QuotaByCounterKeysClient is the apiManagement Client 29type QuotaByCounterKeysClient struct { 30 BaseClient 31} 32 33// NewQuotaByCounterKeysClient creates an instance of the QuotaByCounterKeysClient client. 34func NewQuotaByCounterKeysClient(subscriptionID string) QuotaByCounterKeysClient { 35 return NewQuotaByCounterKeysClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewQuotaByCounterKeysClientWithBaseURI creates an instance of the QuotaByCounterKeysClient client. 39func NewQuotaByCounterKeysClientWithBaseURI(baseURI string, subscriptionID string) QuotaByCounterKeysClient { 40 return QuotaByCounterKeysClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// ListByService lists a collection of current quota counter periods associated with the counter-key configured in the 44// policy on the specified service instance. The api does not support paging yet. 45// Parameters: 46// resourceGroupName - the name of the resource group. 47// serviceName - the name of the API Management service. 48// quotaCounterKey - quota counter key identifier. 49func (client QuotaByCounterKeysClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, quotaCounterKey string) (result QuotaCounterCollection, err error) { 50 if err := validation.Validate([]validation.Validation{ 51 {TargetValue: serviceName, 52 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 53 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 54 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 55 return result, validation.NewError("apimanagement.QuotaByCounterKeysClient", "ListByService", err.Error()) 56 } 57 58 req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, quotaCounterKey) 59 if err != nil { 60 err = autorest.NewErrorWithError(err, "apimanagement.QuotaByCounterKeysClient", "ListByService", nil, "Failure preparing request") 61 return 62 } 63 64 resp, err := client.ListByServiceSender(req) 65 if err != nil { 66 result.Response = autorest.Response{Response: resp} 67 err = autorest.NewErrorWithError(err, "apimanagement.QuotaByCounterKeysClient", "ListByService", resp, "Failure sending request") 68 return 69 } 70 71 result, err = client.ListByServiceResponder(resp) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "apimanagement.QuotaByCounterKeysClient", "ListByService", resp, "Failure responding to request") 74 } 75 76 return 77} 78 79// ListByServicePreparer prepares the ListByService request. 80func (client QuotaByCounterKeysClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, quotaCounterKey string) (*http.Request, error) { 81 pathParameters := map[string]interface{}{ 82 "quotaCounterKey": autorest.Encode("path", quotaCounterKey), 83 "resourceGroupName": autorest.Encode("path", resourceGroupName), 84 "serviceName": autorest.Encode("path", serviceName), 85 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 86 } 87 88 const APIVersion = "2016-07-07" 89 queryParameters := map[string]interface{}{ 90 "api-version": APIVersion, 91 } 92 93 preparer := autorest.CreatePreparer( 94 autorest.AsGet(), 95 autorest.WithBaseURL(client.BaseURI), 96 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/quotas/{quotaCounterKey}", pathParameters), 97 autorest.WithQueryParameters(queryParameters)) 98 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 99} 100 101// ListByServiceSender sends the ListByService request. The method will close the 102// http.Response Body if it receives an error. 103func (client QuotaByCounterKeysClient) ListByServiceSender(req *http.Request) (*http.Response, error) { 104 return autorest.SendWithSender(client, req, 105 azure.DoRetryWithRegistration(client.Client)) 106} 107 108// ListByServiceResponder handles the response to the ListByService request. The method always 109// closes the http.Response Body. 110func (client QuotaByCounterKeysClient) ListByServiceResponder(resp *http.Response) (result QuotaCounterCollection, err error) { 111 err = autorest.Respond( 112 resp, 113 client.ByInspecting(), 114 azure.WithErrorUnlessStatusCode(http.StatusOK), 115 autorest.ByUnmarshallingJSON(&result), 116 autorest.ByClosing()) 117 result.Response = autorest.Response{Response: resp} 118 return 119} 120 121// Update updates all the quota counter values specified with the existing quota counter key to a value in the 122// specified service instance. This should be used for reset of the quota counter values. 123// Parameters: 124// resourceGroupName - the name of the resource group. 125// serviceName - the name of the API Management service. 126// quotaCounterKey - quota counter key identifier. 127// parameters - the value of the quota counter to be applied to all quota counter periods. 128func (client QuotaByCounterKeysClient) Update(ctx context.Context, resourceGroupName string, serviceName string, quotaCounterKey string, parameters QuotaCounterValueContract) (result autorest.Response, err error) { 129 if err := validation.Validate([]validation.Validation{ 130 {TargetValue: serviceName, 131 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 132 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 133 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 134 return result, validation.NewError("apimanagement.QuotaByCounterKeysClient", "Update", err.Error()) 135 } 136 137 req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, quotaCounterKey, parameters) 138 if err != nil { 139 err = autorest.NewErrorWithError(err, "apimanagement.QuotaByCounterKeysClient", "Update", nil, "Failure preparing request") 140 return 141 } 142 143 resp, err := client.UpdateSender(req) 144 if err != nil { 145 result.Response = resp 146 err = autorest.NewErrorWithError(err, "apimanagement.QuotaByCounterKeysClient", "Update", resp, "Failure sending request") 147 return 148 } 149 150 result, err = client.UpdateResponder(resp) 151 if err != nil { 152 err = autorest.NewErrorWithError(err, "apimanagement.QuotaByCounterKeysClient", "Update", resp, "Failure responding to request") 153 } 154 155 return 156} 157 158// UpdatePreparer prepares the Update request. 159func (client QuotaByCounterKeysClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, quotaCounterKey string, parameters QuotaCounterValueContract) (*http.Request, error) { 160 pathParameters := map[string]interface{}{ 161 "quotaCounterKey": autorest.Encode("path", quotaCounterKey), 162 "resourceGroupName": autorest.Encode("path", resourceGroupName), 163 "serviceName": autorest.Encode("path", serviceName), 164 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 165 } 166 167 const APIVersion = "2016-07-07" 168 queryParameters := map[string]interface{}{ 169 "api-version": APIVersion, 170 } 171 172 preparer := autorest.CreatePreparer( 173 autorest.AsContentType("application/json; charset=utf-8"), 174 autorest.AsPatch(), 175 autorest.WithBaseURL(client.BaseURI), 176 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/quotas/{quotaCounterKey}", pathParameters), 177 autorest.WithJSON(parameters), 178 autorest.WithQueryParameters(queryParameters)) 179 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 180} 181 182// UpdateSender sends the Update request. The method will close the 183// http.Response Body if it receives an error. 184func (client QuotaByCounterKeysClient) UpdateSender(req *http.Request) (*http.Response, error) { 185 return autorest.SendWithSender(client, req, 186 azure.DoRetryWithRegistration(client.Client)) 187} 188 189// UpdateResponder handles the response to the Update request. The method always 190// closes the http.Response Body. 191func (client QuotaByCounterKeysClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { 192 err = autorest.Respond( 193 resp, 194 client.ByInspecting(), 195 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 196 autorest.ByClosing()) 197 result.Response = resp 198 return 199} 200