1package backup
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/tracing"
14	"net/http"
15)
16
17// ProtectionContainersGroupClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
18type ProtectionContainersGroupClient struct {
19	BaseClient
20}
21
22// NewProtectionContainersGroupClient creates an instance of the ProtectionContainersGroupClient client.
23func NewProtectionContainersGroupClient(subscriptionID string) ProtectionContainersGroupClient {
24	return NewProtectionContainersGroupClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewProtectionContainersGroupClientWithBaseURI creates an instance of the ProtectionContainersGroupClient client
28// using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
29// clouds, Azure stack).
30func NewProtectionContainersGroupClientWithBaseURI(baseURI string, subscriptionID string) ProtectionContainersGroupClient {
31	return ProtectionContainersGroupClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// List lists the containers registered to Recovery Services Vault.
35// Parameters:
36// vaultName - the name of the recovery services vault.
37// resourceGroupName - the name of the resource group where the recovery services vault is present.
38// filter - oData filter options.
39func (client ProtectionContainersGroupClient) List(ctx context.Context, vaultName string, resourceGroupName string, filter string) (result ProtectionContainerResourceListPage, err error) {
40	if tracing.IsEnabled() {
41		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionContainersGroupClient.List")
42		defer func() {
43			sc := -1
44			if result.pcrl.Response.Response != nil {
45				sc = result.pcrl.Response.Response.StatusCode
46			}
47			tracing.EndSpan(ctx, sc, err)
48		}()
49	}
50	result.fn = client.listNextResults
51	req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, filter)
52	if err != nil {
53		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersGroupClient", "List", nil, "Failure preparing request")
54		return
55	}
56
57	resp, err := client.ListSender(req)
58	if err != nil {
59		result.pcrl.Response = autorest.Response{Response: resp}
60		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersGroupClient", "List", resp, "Failure sending request")
61		return
62	}
63
64	result.pcrl, err = client.ListResponder(resp)
65	if err != nil {
66		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersGroupClient", "List", resp, "Failure responding to request")
67		return
68	}
69	if result.pcrl.hasNextLink() && result.pcrl.IsEmpty() {
70		err = result.NextWithContext(ctx)
71		return
72	}
73
74	return
75}
76
77// ListPreparer prepares the List request.
78func (client ProtectionContainersGroupClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, filter string) (*http.Request, error) {
79	pathParameters := map[string]interface{}{
80		"resourceGroupName": autorest.Encode("path", resourceGroupName),
81		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
82		"vaultName":         autorest.Encode("path", vaultName),
83	}
84
85	const APIVersion = "2021-01-01"
86	queryParameters := map[string]interface{}{
87		"api-version": APIVersion,
88	}
89	if len(filter) > 0 {
90		queryParameters["$filter"] = autorest.Encode("query", filter)
91	}
92
93	preparer := autorest.CreatePreparer(
94		autorest.AsGet(),
95		autorest.WithBaseURL(client.BaseURI),
96		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupProtectionContainers", 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 ProtectionContainersGroupClient) 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 ProtectionContainersGroupClient) ListResponder(resp *http.Response) (result ProtectionContainerResourceList, err error) {
110	err = autorest.Respond(
111		resp,
112		azure.WithErrorUnlessStatusCode(http.StatusOK),
113		autorest.ByUnmarshallingJSON(&result),
114		autorest.ByClosing())
115	result.Response = autorest.Response{Response: resp}
116	return
117}
118
119// listNextResults retrieves the next set of results, if any.
120func (client ProtectionContainersGroupClient) listNextResults(ctx context.Context, lastResults ProtectionContainerResourceList) (result ProtectionContainerResourceList, err error) {
121	req, err := lastResults.protectionContainerResourceListPreparer(ctx)
122	if err != nil {
123		return result, autorest.NewErrorWithError(err, "backup.ProtectionContainersGroupClient", "listNextResults", nil, "Failure preparing next results request")
124	}
125	if req == nil {
126		return
127	}
128	resp, err := client.ListSender(req)
129	if err != nil {
130		result.Response = autorest.Response{Response: resp}
131		return result, autorest.NewErrorWithError(err, "backup.ProtectionContainersGroupClient", "listNextResults", resp, "Failure sending next results request")
132	}
133	result, err = client.ListResponder(resp)
134	if err != nil {
135		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersGroupClient", "listNextResults", resp, "Failure responding to next results request")
136	}
137	return
138}
139
140// ListComplete enumerates all values, automatically crossing page boundaries as required.
141func (client ProtectionContainersGroupClient) ListComplete(ctx context.Context, vaultName string, resourceGroupName string, filter string) (result ProtectionContainerResourceListIterator, err error) {
142	if tracing.IsEnabled() {
143		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionContainersGroupClient.List")
144		defer func() {
145			sc := -1
146			if result.Response().Response.Response != nil {
147				sc = result.page.Response().Response.Response.StatusCode
148			}
149			tracing.EndSpan(ctx, sc, err)
150		}()
151	}
152	result.page, err = client.List(ctx, vaultName, resourceGroupName, filter)
153	return
154}
155