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 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// APIRevisionClient is the apiManagement Client 30type APIRevisionClient struct { 31 BaseClient 32} 33 34// NewAPIRevisionClient creates an instance of the APIRevisionClient client. 35func NewAPIRevisionClient(subscriptionID string) APIRevisionClient { 36 return NewAPIRevisionClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewAPIRevisionClientWithBaseURI creates an instance of the APIRevisionClient client using a custom endpoint. Use 40// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewAPIRevisionClientWithBaseURI(baseURI string, subscriptionID string) APIRevisionClient { 42 return APIRevisionClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// ListByService lists all revisions of an API. 46// Parameters: 47// resourceGroupName - the name of the resource group. 48// serviceName - the name of the API Management service. 49// apiid - API identifier. Must be unique in the current API Management service instance. 50// filter - | Field | Usage | Supported operators | Supported functions 51// |</br>|-------------|-------------|-------------|-------------|</br>| apiRevision | filter | ge, le, eq, ne, 52// gt, lt | substringof, contains, startswith, endswith | </br> 53// top - number of records to return. 54// skip - number of records to skip. 55func (client APIRevisionClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result APIRevisionCollectionPage, err error) { 56 if tracing.IsEnabled() { 57 ctx = tracing.StartSpan(ctx, fqdn+"/APIRevisionClient.ListByService") 58 defer func() { 59 sc := -1 60 if result.arc.Response.Response != nil { 61 sc = result.arc.Response.Response.StatusCode 62 } 63 tracing.EndSpan(ctx, sc, err) 64 }() 65 } 66 if err := validation.Validate([]validation.Validation{ 67 {TargetValue: serviceName, 68 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 69 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 70 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 71 {TargetValue: apiid, 72 Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 80, Chain: nil}, 73 {Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 74 {TargetValue: top, 75 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 76 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}}, 77 {TargetValue: skip, 78 Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false, 79 Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { 80 return result, validation.NewError("apimanagement.APIRevisionClient", "ListByService", err.Error()) 81 } 82 83 result.fn = client.listByServiceNextResults 84 req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, apiid, filter, top, skip) 85 if err != nil { 86 err = autorest.NewErrorWithError(err, "apimanagement.APIRevisionClient", "ListByService", nil, "Failure preparing request") 87 return 88 } 89 90 resp, err := client.ListByServiceSender(req) 91 if err != nil { 92 result.arc.Response = autorest.Response{Response: resp} 93 err = autorest.NewErrorWithError(err, "apimanagement.APIRevisionClient", "ListByService", resp, "Failure sending request") 94 return 95 } 96 97 result.arc, err = client.ListByServiceResponder(resp) 98 if err != nil { 99 err = autorest.NewErrorWithError(err, "apimanagement.APIRevisionClient", "ListByService", resp, "Failure responding to request") 100 } 101 102 return 103} 104 105// ListByServicePreparer prepares the ListByService request. 106func (client APIRevisionClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (*http.Request, error) { 107 pathParameters := map[string]interface{}{ 108 "apiId": autorest.Encode("path", apiid), 109 "resourceGroupName": autorest.Encode("path", resourceGroupName), 110 "serviceName": autorest.Encode("path", serviceName), 111 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 112 } 113 114 const APIVersion = "2019-12-01" 115 queryParameters := map[string]interface{}{ 116 "api-version": APIVersion, 117 } 118 if len(filter) > 0 { 119 queryParameters["$filter"] = autorest.Encode("query", filter) 120 } 121 if top != nil { 122 queryParameters["$top"] = autorest.Encode("query", *top) 123 } 124 if skip != nil { 125 queryParameters["$skip"] = autorest.Encode("query", *skip) 126 } 127 128 preparer := autorest.CreatePreparer( 129 autorest.AsGet(), 130 autorest.WithBaseURL(client.BaseURI), 131 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/revisions", pathParameters), 132 autorest.WithQueryParameters(queryParameters)) 133 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 134} 135 136// ListByServiceSender sends the ListByService request. The method will close the 137// http.Response Body if it receives an error. 138func (client APIRevisionClient) ListByServiceSender(req *http.Request) (*http.Response, error) { 139 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 140} 141 142// ListByServiceResponder handles the response to the ListByService request. The method always 143// closes the http.Response Body. 144func (client APIRevisionClient) ListByServiceResponder(resp *http.Response) (result APIRevisionCollection, err error) { 145 err = autorest.Respond( 146 resp, 147 client.ByInspecting(), 148 azure.WithErrorUnlessStatusCode(http.StatusOK), 149 autorest.ByUnmarshallingJSON(&result), 150 autorest.ByClosing()) 151 result.Response = autorest.Response{Response: resp} 152 return 153} 154 155// listByServiceNextResults retrieves the next set of results, if any. 156func (client APIRevisionClient) listByServiceNextResults(ctx context.Context, lastResults APIRevisionCollection) (result APIRevisionCollection, err error) { 157 req, err := lastResults.aPIRevisionCollectionPreparer(ctx) 158 if err != nil { 159 return result, autorest.NewErrorWithError(err, "apimanagement.APIRevisionClient", "listByServiceNextResults", nil, "Failure preparing next results request") 160 } 161 if req == nil { 162 return 163 } 164 resp, err := client.ListByServiceSender(req) 165 if err != nil { 166 result.Response = autorest.Response{Response: resp} 167 return result, autorest.NewErrorWithError(err, "apimanagement.APIRevisionClient", "listByServiceNextResults", resp, "Failure sending next results request") 168 } 169 result, err = client.ListByServiceResponder(resp) 170 if err != nil { 171 err = autorest.NewErrorWithError(err, "apimanagement.APIRevisionClient", "listByServiceNextResults", resp, "Failure responding to next results request") 172 } 173 return 174} 175 176// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required. 177func (client APIRevisionClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, filter string, top *int32, skip *int32) (result APIRevisionCollectionIterator, err error) { 178 if tracing.IsEnabled() { 179 ctx = tracing.StartSpan(ctx, fqdn+"/APIRevisionClient.ListByService") 180 defer func() { 181 sc := -1 182 if result.Response().Response.Response != nil { 183 sc = result.page.Response().Response.Response.StatusCode 184 } 185 tracing.EndSpan(ctx, sc, err) 186 }() 187 } 188 result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, apiid, filter, top, skip) 189 return 190} 191