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// PolicySnippetsClient is the apiManagement Client 29type PolicySnippetsClient struct { 30 BaseClient 31} 32 33// NewPolicySnippetsClient creates an instance of the PolicySnippetsClient client. 34func NewPolicySnippetsClient(subscriptionID string) PolicySnippetsClient { 35 return NewPolicySnippetsClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewPolicySnippetsClientWithBaseURI creates an instance of the PolicySnippetsClient client. 39func NewPolicySnippetsClientWithBaseURI(baseURI string, subscriptionID string) PolicySnippetsClient { 40 return PolicySnippetsClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// ListByService lists all policy snippets. 44// Parameters: 45// resourceGroupName - the name of the resource group. 46// serviceName - the name of the API Management service. 47// scope - policy scope. 48func (client PolicySnippetsClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, scope PolicyScopeContract) (result PolicySnippetsCollection, err error) { 49 if err := validation.Validate([]validation.Validation{ 50 {TargetValue: serviceName, 51 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 52 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 53 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 54 return result, validation.NewError("apimanagement.PolicySnippetsClient", "ListByService", err.Error()) 55 } 56 57 req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, scope) 58 if err != nil { 59 err = autorest.NewErrorWithError(err, "apimanagement.PolicySnippetsClient", "ListByService", nil, "Failure preparing request") 60 return 61 } 62 63 resp, err := client.ListByServiceSender(req) 64 if err != nil { 65 result.Response = autorest.Response{Response: resp} 66 err = autorest.NewErrorWithError(err, "apimanagement.PolicySnippetsClient", "ListByService", resp, "Failure sending request") 67 return 68 } 69 70 result, err = client.ListByServiceResponder(resp) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "apimanagement.PolicySnippetsClient", "ListByService", resp, "Failure responding to request") 73 } 74 75 return 76} 77 78// ListByServicePreparer prepares the ListByService request. 79func (client PolicySnippetsClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, scope PolicyScopeContract) (*http.Request, error) { 80 pathParameters := map[string]interface{}{ 81 "resourceGroupName": autorest.Encode("path", resourceGroupName), 82 "serviceName": autorest.Encode("path", serviceName), 83 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 84 } 85 86 const APIVersion = "2016-10-10" 87 queryParameters := map[string]interface{}{ 88 "api-version": APIVersion, 89 } 90 if len(string(scope)) > 0 { 91 queryParameters["scope"] = autorest.Encode("query", scope) 92 } 93 94 preparer := autorest.CreatePreparer( 95 autorest.AsGet(), 96 autorest.WithBaseURL(client.BaseURI), 97 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/policySnippets", pathParameters), 98 autorest.WithQueryParameters(queryParameters)) 99 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 100} 101 102// ListByServiceSender sends the ListByService request. The method will close the 103// http.Response Body if it receives an error. 104func (client PolicySnippetsClient) ListByServiceSender(req *http.Request) (*http.Response, error) { 105 return autorest.SendWithSender(client, req, 106 azure.DoRetryWithRegistration(client.Client)) 107} 108 109// ListByServiceResponder handles the response to the ListByService request. The method always 110// closes the http.Response Body. 111func (client PolicySnippetsClient) ListByServiceResponder(resp *http.Response) (result PolicySnippetsCollection, err error) { 112 err = autorest.Respond( 113 resp, 114 client.ByInspecting(), 115 azure.WithErrorUnlessStatusCode(http.StatusOK), 116 autorest.ByUnmarshallingJSON(&result), 117 autorest.ByClosing()) 118 result.Response = autorest.Response{Response: resp} 119 return 120} 121