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