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