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	}
79
80	return
81}
82
83// ListPreparer prepares the List request.
84func (client AvailableResourceGroupDelegationsClient) ListPreparer(ctx context.Context, location string, resourceGroupName string) (*http.Request, error) {
85	pathParameters := map[string]interface{}{
86		"location":          autorest.Encode("path", location),
87		"resourceGroupName": autorest.Encode("path", resourceGroupName),
88		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
89	}
90
91	const APIVersion = "2020-04-01"
92	queryParameters := map[string]interface{}{
93		"api-version": APIVersion,
94	}
95
96	preparer := autorest.CreatePreparer(
97		autorest.AsGet(),
98		autorest.WithBaseURL(client.BaseURI),
99		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/locations/{location}/availableDelegations", pathParameters),
100		autorest.WithQueryParameters(queryParameters))
101	return preparer.Prepare((&http.Request{}).WithContext(ctx))
102}
103
104// ListSender sends the List request. The method will close the
105// http.Response Body if it receives an error.
106func (client AvailableResourceGroupDelegationsClient) ListSender(req *http.Request) (*http.Response, error) {
107	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
108}
109
110// ListResponder handles the response to the List request. The method always
111// closes the http.Response Body.
112func (client AvailableResourceGroupDelegationsClient) ListResponder(resp *http.Response) (result AvailableDelegationsResult, err error) {
113	err = autorest.Respond(
114		resp,
115		client.ByInspecting(),
116		azure.WithErrorUnlessStatusCode(http.StatusOK),
117		autorest.ByUnmarshallingJSON(&result),
118		autorest.ByClosing())
119	result.Response = autorest.Response{Response: resp}
120	return
121}
122
123// listNextResults retrieves the next set of results, if any.
124func (client AvailableResourceGroupDelegationsClient) listNextResults(ctx context.Context, lastResults AvailableDelegationsResult) (result AvailableDelegationsResult, err error) {
125	req, err := lastResults.availableDelegationsResultPreparer(ctx)
126	if err != nil {
127		return result, autorest.NewErrorWithError(err, "network.AvailableResourceGroupDelegationsClient", "listNextResults", nil, "Failure preparing next results request")
128	}
129	if req == nil {
130		return
131	}
132	resp, err := client.ListSender(req)
133	if err != nil {
134		result.Response = autorest.Response{Response: resp}
135		return result, autorest.NewErrorWithError(err, "network.AvailableResourceGroupDelegationsClient", "listNextResults", resp, "Failure sending next results request")
136	}
137	result, err = client.ListResponder(resp)
138	if err != nil {
139		err = autorest.NewErrorWithError(err, "network.AvailableResourceGroupDelegationsClient", "listNextResults", resp, "Failure responding to next results request")
140	}
141	return
142}
143
144// ListComplete enumerates all values, automatically crossing page boundaries as required.
145func (client AvailableResourceGroupDelegationsClient) ListComplete(ctx context.Context, location string, resourceGroupName string) (result AvailableDelegationsResultIterator, err error) {
146	if tracing.IsEnabled() {
147		ctx = tracing.StartSpan(ctx, fqdn+"/AvailableResourceGroupDelegationsClient.List")
148		defer func() {
149			sc := -1
150			if result.Response().Response.Response != nil {
151				sc = result.page.Response().Response.Response.StatusCode
152			}
153			tracing.EndSpan(ctx, sc, err)
154		}()
155	}
156	result.page, err = client.List(ctx, location, resourceGroupName)
157	return
158}
159