1package network 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/tracing" 25 "net/http" 26) 27 28// AvailableDelegationsClient is the network Client 29type AvailableDelegationsClient struct { 30 BaseClient 31} 32 33// NewAvailableDelegationsClient creates an instance of the AvailableDelegationsClient client. 34func NewAvailableDelegationsClient(subscriptionID string) AvailableDelegationsClient { 35 return NewAvailableDelegationsClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewAvailableDelegationsClientWithBaseURI creates an instance of the AvailableDelegationsClient client using a custom 39// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 40// stack). 41func NewAvailableDelegationsClientWithBaseURI(baseURI string, subscriptionID string) AvailableDelegationsClient { 42 return AvailableDelegationsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// List gets all of the available subnet delegations for this subscription in this region. 46// Parameters: 47// location - the location of the subnet. 48func (client AvailableDelegationsClient) List(ctx context.Context, location string) (result AvailableDelegationsResultPage, err error) { 49 if tracing.IsEnabled() { 50 ctx = tracing.StartSpan(ctx, fqdn+"/AvailableDelegationsClient.List") 51 defer func() { 52 sc := -1 53 if result.adr.Response.Response != nil { 54 sc = result.adr.Response.Response.StatusCode 55 } 56 tracing.EndSpan(ctx, sc, err) 57 }() 58 } 59 result.fn = client.listNextResults 60 req, err := client.ListPreparer(ctx, location) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "network.AvailableDelegationsClient", "List", nil, "Failure preparing request") 63 return 64 } 65 66 resp, err := client.ListSender(req) 67 if err != nil { 68 result.adr.Response = autorest.Response{Response: resp} 69 err = autorest.NewErrorWithError(err, "network.AvailableDelegationsClient", "List", resp, "Failure sending request") 70 return 71 } 72 73 result.adr, err = client.ListResponder(resp) 74 if err != nil { 75 err = autorest.NewErrorWithError(err, "network.AvailableDelegationsClient", "List", resp, "Failure responding to request") 76 } 77 78 return 79} 80 81// ListPreparer prepares the List request. 82func (client AvailableDelegationsClient) ListPreparer(ctx context.Context, location string) (*http.Request, error) { 83 pathParameters := map[string]interface{}{ 84 "location": autorest.Encode("path", location), 85 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 86 } 87 88 const APIVersion = "2020-04-01" 89 queryParameters := map[string]interface{}{ 90 "api-version": APIVersion, 91 } 92 93 preparer := autorest.CreatePreparer( 94 autorest.AsGet(), 95 autorest.WithBaseURL(client.BaseURI), 96 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/availableDelegations", pathParameters), 97 autorest.WithQueryParameters(queryParameters)) 98 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 99} 100 101// ListSender sends the List request. The method will close the 102// http.Response Body if it receives an error. 103func (client AvailableDelegationsClient) ListSender(req *http.Request) (*http.Response, error) { 104 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 105} 106 107// ListResponder handles the response to the List request. The method always 108// closes the http.Response Body. 109func (client AvailableDelegationsClient) ListResponder(resp *http.Response) (result AvailableDelegationsResult, err error) { 110 err = autorest.Respond( 111 resp, 112 client.ByInspecting(), 113 azure.WithErrorUnlessStatusCode(http.StatusOK), 114 autorest.ByUnmarshallingJSON(&result), 115 autorest.ByClosing()) 116 result.Response = autorest.Response{Response: resp} 117 return 118} 119 120// listNextResults retrieves the next set of results, if any. 121func (client AvailableDelegationsClient) listNextResults(ctx context.Context, lastResults AvailableDelegationsResult) (result AvailableDelegationsResult, err error) { 122 req, err := lastResults.availableDelegationsResultPreparer(ctx) 123 if err != nil { 124 return result, autorest.NewErrorWithError(err, "network.AvailableDelegationsClient", "listNextResults", nil, "Failure preparing next results request") 125 } 126 if req == nil { 127 return 128 } 129 resp, err := client.ListSender(req) 130 if err != nil { 131 result.Response = autorest.Response{Response: resp} 132 return result, autorest.NewErrorWithError(err, "network.AvailableDelegationsClient", "listNextResults", resp, "Failure sending next results request") 133 } 134 result, err = client.ListResponder(resp) 135 if err != nil { 136 err = autorest.NewErrorWithError(err, "network.AvailableDelegationsClient", "listNextResults", resp, "Failure responding to next results request") 137 } 138 return 139} 140 141// ListComplete enumerates all values, automatically crossing page boundaries as required. 142func (client AvailableDelegationsClient) ListComplete(ctx context.Context, location string) (result AvailableDelegationsResultIterator, err error) { 143 if tracing.IsEnabled() { 144 ctx = tracing.StartSpan(ctx, fqdn+"/AvailableDelegationsClient.List") 145 defer func() { 146 sc := -1 147 if result.Response().Response.Response != nil { 148 sc = result.page.Response().Response.Response.StatusCode 149 } 150 tracing.EndSpan(ctx, sc, err) 151 }() 152 } 153 result.page, err = client.List(ctx, location) 154 return 155} 156