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// PortalSettingsClient is the apiManagement Client 30type PortalSettingsClient struct { 31 BaseClient 32} 33 34// NewPortalSettingsClient creates an instance of the PortalSettingsClient client. 35func NewPortalSettingsClient(subscriptionID string) PortalSettingsClient { 36 return NewPortalSettingsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewPortalSettingsClientWithBaseURI creates an instance of the PortalSettingsClient client using a custom endpoint. 40// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewPortalSettingsClientWithBaseURI(baseURI string, subscriptionID string) PortalSettingsClient { 42 return PortalSettingsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// ListByService lists a collection of portalsettings defined within a service instance.. 46// Parameters: 47// resourceGroupName - the name of the resource group. 48// serviceName - the name of the API Management service. 49func (client PortalSettingsClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string) (result PortalSettingsCollection, err error) { 50 if tracing.IsEnabled() { 51 ctx = tracing.StartSpan(ctx, fqdn+"/PortalSettingsClient.ListByService") 52 defer func() { 53 sc := -1 54 if result.Response.Response != nil { 55 sc = result.Response.Response.StatusCode 56 } 57 tracing.EndSpan(ctx, sc, err) 58 }() 59 } 60 if err := validation.Validate([]validation.Validation{ 61 {TargetValue: serviceName, 62 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 63 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 64 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 65 return result, validation.NewError("apimanagement.PortalSettingsClient", "ListByService", err.Error()) 66 } 67 68 req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName) 69 if err != nil { 70 err = autorest.NewErrorWithError(err, "apimanagement.PortalSettingsClient", "ListByService", nil, "Failure preparing request") 71 return 72 } 73 74 resp, err := client.ListByServiceSender(req) 75 if err != nil { 76 result.Response = autorest.Response{Response: resp} 77 err = autorest.NewErrorWithError(err, "apimanagement.PortalSettingsClient", "ListByService", resp, "Failure sending request") 78 return 79 } 80 81 result, err = client.ListByServiceResponder(resp) 82 if err != nil { 83 err = autorest.NewErrorWithError(err, "apimanagement.PortalSettingsClient", "ListByService", resp, "Failure responding to request") 84 return 85 } 86 87 return 88} 89 90// ListByServicePreparer prepares the ListByService request. 91func (client PortalSettingsClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) { 92 pathParameters := map[string]interface{}{ 93 "resourceGroupName": autorest.Encode("path", resourceGroupName), 94 "serviceName": autorest.Encode("path", serviceName), 95 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 96 } 97 98 const APIVersion = "2020-12-01" 99 queryParameters := map[string]interface{}{ 100 "api-version": APIVersion, 101 } 102 103 preparer := autorest.CreatePreparer( 104 autorest.AsGet(), 105 autorest.WithBaseURL(client.BaseURI), 106 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/portalsettings", pathParameters), 107 autorest.WithQueryParameters(queryParameters)) 108 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 109} 110 111// ListByServiceSender sends the ListByService request. The method will close the 112// http.Response Body if it receives an error. 113func (client PortalSettingsClient) ListByServiceSender(req *http.Request) (*http.Response, error) { 114 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 115} 116 117// ListByServiceResponder handles the response to the ListByService request. The method always 118// closes the http.Response Body. 119func (client PortalSettingsClient) ListByServiceResponder(resp *http.Response) (result PortalSettingsCollection, err error) { 120 err = autorest.Respond( 121 resp, 122 azure.WithErrorUnlessStatusCode(http.StatusOK), 123 autorest.ByUnmarshallingJSON(&result), 124 autorest.ByClosing()) 125 result.Response = autorest.Response{Response: resp} 126 return 127} 128