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