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