1package backup
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// RecoveryPointsClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
29type RecoveryPointsClient struct {
30	BaseClient
31}
32
33// NewRecoveryPointsClient creates an instance of the RecoveryPointsClient client.
34func NewRecoveryPointsClient(subscriptionID string) RecoveryPointsClient {
35	return NewRecoveryPointsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewRecoveryPointsClientWithBaseURI creates an instance of the RecoveryPointsClient client using a custom endpoint.
39// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
40func NewRecoveryPointsClientWithBaseURI(baseURI string, subscriptionID string) RecoveryPointsClient {
41	return RecoveryPointsClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// Get provides the information of the backed up data identified using RecoveryPointID. This is an asynchronous
45// operation.
46// To know the status of the operation, call the GetProtectedItemOperationResult API.
47// Parameters:
48// vaultName - the name of the recovery services vault.
49// resourceGroupName - the name of the resource group where the recovery services vault is present.
50// fabricName - fabric name associated with backed up item.
51// containerName - container name associated with backed up item.
52// protectedItemName - backed up item name whose backup data needs to be fetched.
53// recoveryPointID - recoveryPointID represents the backed up data to be fetched.
54func (client RecoveryPointsClient) Get(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, recoveryPointID string) (result RecoveryPointResource, err error) {
55	if tracing.IsEnabled() {
56		ctx = tracing.StartSpan(ctx, fqdn+"/RecoveryPointsClient.Get")
57		defer func() {
58			sc := -1
59			if result.Response.Response != nil {
60				sc = result.Response.Response.StatusCode
61			}
62			tracing.EndSpan(ctx, sc, err)
63		}()
64	}
65	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, recoveryPointID)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "Get", nil, "Failure preparing request")
68		return
69	}
70
71	resp, err := client.GetSender(req)
72	if err != nil {
73		result.Response = autorest.Response{Response: resp}
74		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "Get", resp, "Failure sending request")
75		return
76	}
77
78	result, err = client.GetResponder(resp)
79	if err != nil {
80		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "Get", resp, "Failure responding to request")
81	}
82
83	return
84}
85
86// GetPreparer prepares the Get request.
87func (client RecoveryPointsClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, recoveryPointID string) (*http.Request, error) {
88	pathParameters := map[string]interface{}{
89		"containerName":     autorest.Encode("path", containerName),
90		"fabricName":        autorest.Encode("path", fabricName),
91		"protectedItemName": autorest.Encode("path", protectedItemName),
92		"recoveryPointId":   autorest.Encode("path", recoveryPointID),
93		"resourceGroupName": autorest.Encode("path", resourceGroupName),
94		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
95		"vaultName":         autorest.Encode("path", vaultName),
96	}
97
98	const APIVersion = "2019-06-15"
99	queryParameters := map[string]interface{}{
100		"api-version": APIVersion,
101	}
102
103	preparer := autorest.CreatePreparer(
104		autorest.AsGet(),
105		autorest.WithBaseURL(client.BaseURI),
106		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/recoveryPoints/{recoveryPointId}", pathParameters),
107		autorest.WithQueryParameters(queryParameters))
108	return preparer.Prepare((&http.Request{}).WithContext(ctx))
109}
110
111// GetSender sends the Get request. The method will close the
112// http.Response Body if it receives an error.
113func (client RecoveryPointsClient) GetSender(req *http.Request) (*http.Response, error) {
114	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
115}
116
117// GetResponder handles the response to the Get request. The method always
118// closes the http.Response Body.
119func (client RecoveryPointsClient) GetResponder(resp *http.Response) (result RecoveryPointResource, err error) {
120	err = autorest.Respond(
121		resp,
122		client.ByInspecting(),
123		azure.WithErrorUnlessStatusCode(http.StatusOK),
124		autorest.ByUnmarshallingJSON(&result),
125		autorest.ByClosing())
126	result.Response = autorest.Response{Response: resp}
127	return
128}
129
130// List lists the backup copies for the backed up item.
131// Parameters:
132// vaultName - the name of the recovery services vault.
133// resourceGroupName - the name of the resource group where the recovery services vault is present.
134// fabricName - fabric name associated with the backed up item.
135// containerName - container name associated with the backed up item.
136// protectedItemName - backed up item whose backup copies are to be fetched.
137// filter - oData filter options.
138func (client RecoveryPointsClient) List(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, filter string) (result RecoveryPointResourceListPage, err error) {
139	if tracing.IsEnabled() {
140		ctx = tracing.StartSpan(ctx, fqdn+"/RecoveryPointsClient.List")
141		defer func() {
142			sc := -1
143			if result.rprl.Response.Response != nil {
144				sc = result.rprl.Response.Response.StatusCode
145			}
146			tracing.EndSpan(ctx, sc, err)
147		}()
148	}
149	result.fn = client.listNextResults
150	req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, filter)
151	if err != nil {
152		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "List", nil, "Failure preparing request")
153		return
154	}
155
156	resp, err := client.ListSender(req)
157	if err != nil {
158		result.rprl.Response = autorest.Response{Response: resp}
159		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "List", resp, "Failure sending request")
160		return
161	}
162
163	result.rprl, err = client.ListResponder(resp)
164	if err != nil {
165		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "List", resp, "Failure responding to request")
166	}
167
168	return
169}
170
171// ListPreparer prepares the List request.
172func (client RecoveryPointsClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, filter string) (*http.Request, error) {
173	pathParameters := map[string]interface{}{
174		"containerName":     autorest.Encode("path", containerName),
175		"fabricName":        autorest.Encode("path", fabricName),
176		"protectedItemName": autorest.Encode("path", protectedItemName),
177		"resourceGroupName": autorest.Encode("path", resourceGroupName),
178		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
179		"vaultName":         autorest.Encode("path", vaultName),
180	}
181
182	const APIVersion = "2019-06-15"
183	queryParameters := map[string]interface{}{
184		"api-version": APIVersion,
185	}
186	if len(filter) > 0 {
187		queryParameters["$filter"] = autorest.Encode("query", filter)
188	}
189
190	preparer := autorest.CreatePreparer(
191		autorest.AsGet(),
192		autorest.WithBaseURL(client.BaseURI),
193		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/recoveryPoints", pathParameters),
194		autorest.WithQueryParameters(queryParameters))
195	return preparer.Prepare((&http.Request{}).WithContext(ctx))
196}
197
198// ListSender sends the List request. The method will close the
199// http.Response Body if it receives an error.
200func (client RecoveryPointsClient) ListSender(req *http.Request) (*http.Response, error) {
201	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
202}
203
204// ListResponder handles the response to the List request. The method always
205// closes the http.Response Body.
206func (client RecoveryPointsClient) ListResponder(resp *http.Response) (result RecoveryPointResourceList, err error) {
207	err = autorest.Respond(
208		resp,
209		client.ByInspecting(),
210		azure.WithErrorUnlessStatusCode(http.StatusOK),
211		autorest.ByUnmarshallingJSON(&result),
212		autorest.ByClosing())
213	result.Response = autorest.Response{Response: resp}
214	return
215}
216
217// listNextResults retrieves the next set of results, if any.
218func (client RecoveryPointsClient) listNextResults(ctx context.Context, lastResults RecoveryPointResourceList) (result RecoveryPointResourceList, err error) {
219	req, err := lastResults.recoveryPointResourceListPreparer(ctx)
220	if err != nil {
221		return result, autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "listNextResults", nil, "Failure preparing next results request")
222	}
223	if req == nil {
224		return
225	}
226	resp, err := client.ListSender(req)
227	if err != nil {
228		result.Response = autorest.Response{Response: resp}
229		return result, autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "listNextResults", resp, "Failure sending next results request")
230	}
231	result, err = client.ListResponder(resp)
232	if err != nil {
233		err = autorest.NewErrorWithError(err, "backup.RecoveryPointsClient", "listNextResults", resp, "Failure responding to next results request")
234	}
235	return
236}
237
238// ListComplete enumerates all values, automatically crossing page boundaries as required.
239func (client RecoveryPointsClient) ListComplete(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, filter string) (result RecoveryPointResourceListIterator, err error) {
240	if tracing.IsEnabled() {
241		ctx = tracing.StartSpan(ctx, fqdn+"/RecoveryPointsClient.List")
242		defer func() {
243			sc := -1
244			if result.Response().Response.Response != nil {
245				sc = result.page.Response().Response.Response.StatusCode
246			}
247			tracing.EndSpan(ctx, sc, err)
248		}()
249	}
250	result.page, err = client.List(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, filter)
251	return
252}
253