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