1package frontdoor
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// PreconfiguredEndpointsClient is the frontDoor Client
19type PreconfiguredEndpointsClient struct {
20	BaseClient
21}
22
23// NewPreconfiguredEndpointsClient creates an instance of the PreconfiguredEndpointsClient client.
24func NewPreconfiguredEndpointsClient(subscriptionID string) PreconfiguredEndpointsClient {
25	return NewPreconfiguredEndpointsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewPreconfiguredEndpointsClientWithBaseURI creates an instance of the PreconfiguredEndpointsClient client using a
29// custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
30// Azure stack).
31func NewPreconfiguredEndpointsClientWithBaseURI(baseURI string, subscriptionID string) PreconfiguredEndpointsClient {
32	return PreconfiguredEndpointsClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// List sends the list request.
36// Parameters:
37// resourceGroupName - name of the Resource group within the Azure subscription.
38// profileName - the Profile identifier associated with the Tenant and Partner
39func (client PreconfiguredEndpointsClient) List(ctx context.Context, resourceGroupName string, profileName string) (result PreconfiguredEndpointListPage, err error) {
40	if tracing.IsEnabled() {
41		ctx = tracing.StartSpan(ctx, fqdn+"/PreconfiguredEndpointsClient.List")
42		defer func() {
43			sc := -1
44			if result.pel.Response.Response != nil {
45				sc = result.pel.Response.Response.StatusCode
46			}
47			tracing.EndSpan(ctx, sc, err)
48		}()
49	}
50	if err := validation.Validate([]validation.Validation{
51		{TargetValue: resourceGroupName,
52			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 80, Chain: nil},
53				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
54				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_\-\(\)\.]*[^\.]$`, Chain: nil}}},
55		{TargetValue: profileName,
56			Constraints: []validation.Constraint{{Target: "profileName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9_\-\(\)\.]*[^\.]$`, Chain: nil}}}}); err != nil {
57		return result, validation.NewError("frontdoor.PreconfiguredEndpointsClient", "List", err.Error())
58	}
59
60	result.fn = client.listNextResults
61	req, err := client.ListPreparer(ctx, resourceGroupName, profileName)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "frontdoor.PreconfiguredEndpointsClient", "List", nil, "Failure preparing request")
64		return
65	}
66
67	resp, err := client.ListSender(req)
68	if err != nil {
69		result.pel.Response = autorest.Response{Response: resp}
70		err = autorest.NewErrorWithError(err, "frontdoor.PreconfiguredEndpointsClient", "List", resp, "Failure sending request")
71		return
72	}
73
74	result.pel, err = client.ListResponder(resp)
75	if err != nil {
76		err = autorest.NewErrorWithError(err, "frontdoor.PreconfiguredEndpointsClient", "List", resp, "Failure responding to request")
77		return
78	}
79	if result.pel.hasNextLink() && result.pel.IsEmpty() {
80		err = result.NextWithContext(ctx)
81		return
82	}
83
84	return
85}
86
87// ListPreparer prepares the List request.
88func (client PreconfiguredEndpointsClient) ListPreparer(ctx context.Context, resourceGroupName string, profileName string) (*http.Request, error) {
89	pathParameters := map[string]interface{}{
90		"profileName":       autorest.Encode("path", profileName),
91		"resourceGroupName": autorest.Encode("path", resourceGroupName),
92		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
93	}
94
95	const APIVersion = "2019-11-01"
96	queryParameters := map[string]interface{}{
97		"api-version": APIVersion,
98	}
99
100	preparer := autorest.CreatePreparer(
101		autorest.AsGet(),
102		autorest.WithBaseURL(client.BaseURI),
103		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/NetworkExperimentProfiles/{profileName}/PreconfiguredEndpoints", pathParameters),
104		autorest.WithQueryParameters(queryParameters))
105	return preparer.Prepare((&http.Request{}).WithContext(ctx))
106}
107
108// ListSender sends the List request. The method will close the
109// http.Response Body if it receives an error.
110func (client PreconfiguredEndpointsClient) ListSender(req *http.Request) (*http.Response, error) {
111	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
112}
113
114// ListResponder handles the response to the List request. The method always
115// closes the http.Response Body.
116func (client PreconfiguredEndpointsClient) ListResponder(resp *http.Response) (result PreconfiguredEndpointList, err error) {
117	err = autorest.Respond(
118		resp,
119		azure.WithErrorUnlessStatusCode(http.StatusOK),
120		autorest.ByUnmarshallingJSON(&result),
121		autorest.ByClosing())
122	result.Response = autorest.Response{Response: resp}
123	return
124}
125
126// listNextResults retrieves the next set of results, if any.
127func (client PreconfiguredEndpointsClient) listNextResults(ctx context.Context, lastResults PreconfiguredEndpointList) (result PreconfiguredEndpointList, err error) {
128	req, err := lastResults.preconfiguredEndpointListPreparer(ctx)
129	if err != nil {
130		return result, autorest.NewErrorWithError(err, "frontdoor.PreconfiguredEndpointsClient", "listNextResults", nil, "Failure preparing next results request")
131	}
132	if req == nil {
133		return
134	}
135	resp, err := client.ListSender(req)
136	if err != nil {
137		result.Response = autorest.Response{Response: resp}
138		return result, autorest.NewErrorWithError(err, "frontdoor.PreconfiguredEndpointsClient", "listNextResults", resp, "Failure sending next results request")
139	}
140	result, err = client.ListResponder(resp)
141	if err != nil {
142		err = autorest.NewErrorWithError(err, "frontdoor.PreconfiguredEndpointsClient", "listNextResults", resp, "Failure responding to next results request")
143	}
144	return
145}
146
147// ListComplete enumerates all values, automatically crossing page boundaries as required.
148func (client PreconfiguredEndpointsClient) ListComplete(ctx context.Context, resourceGroupName string, profileName string) (result PreconfiguredEndpointListIterator, err error) {
149	if tracing.IsEnabled() {
150		ctx = tracing.StartSpan(ctx, fqdn+"/PreconfiguredEndpointsClient.List")
151		defer func() {
152			sc := -1
153			if result.Response().Response.Response != nil {
154				sc = result.page.Response().Response.Response.StatusCode
155			}
156			tracing.EndSpan(ctx, sc, err)
157		}()
158	}
159	result.page, err = client.List(ctx, resourceGroupName, profileName)
160	return
161}
162