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	"net/http"
25)
26
27// ItemLevelRecoveryConnectionsClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
28type ItemLevelRecoveryConnectionsClient struct {
29	BaseClient
30}
31
32// NewItemLevelRecoveryConnectionsClient creates an instance of the ItemLevelRecoveryConnectionsClient client.
33func NewItemLevelRecoveryConnectionsClient(subscriptionID string) ItemLevelRecoveryConnectionsClient {
34	return NewItemLevelRecoveryConnectionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
35}
36
37// NewItemLevelRecoveryConnectionsClientWithBaseURI creates an instance of the ItemLevelRecoveryConnectionsClient
38// client.
39func NewItemLevelRecoveryConnectionsClientWithBaseURI(baseURI string, subscriptionID string) ItemLevelRecoveryConnectionsClient {
40	return ItemLevelRecoveryConnectionsClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// Provision provisions a script which invokes an iSCSI connection to the backup data. Executing this script opens a
44// file
45// explorer displaying all the recoverable files and folders. This is an asynchronous operation. To know the status of
46// provisioning, call 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 the backed up items.
51// containerName - container name associated with the backed up items.
52// protectedItemName - backed up item name whose files/folders are to be restored.
53// recoveryPointID - recovery point ID which represents backed up data. iSCSI connection will be provisioned
54// for this backed up data.
55// parameters - resource ILR request
56func (client ItemLevelRecoveryConnectionsClient) Provision(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, recoveryPointID string, parameters ILRRequestResource) (result autorest.Response, err error) {
57	req, err := client.ProvisionPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, recoveryPointID, parameters)
58	if err != nil {
59		err = autorest.NewErrorWithError(err, "backup.ItemLevelRecoveryConnectionsClient", "Provision", nil, "Failure preparing request")
60		return
61	}
62
63	resp, err := client.ProvisionSender(req)
64	if err != nil {
65		result.Response = resp
66		err = autorest.NewErrorWithError(err, "backup.ItemLevelRecoveryConnectionsClient", "Provision", resp, "Failure sending request")
67		return
68	}
69
70	result, err = client.ProvisionResponder(resp)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "backup.ItemLevelRecoveryConnectionsClient", "Provision", resp, "Failure responding to request")
73	}
74
75	return
76}
77
78// ProvisionPreparer prepares the Provision request.
79func (client ItemLevelRecoveryConnectionsClient) ProvisionPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, recoveryPointID string, parameters ILRRequestResource) (*http.Request, error) {
80	pathParameters := map[string]interface{}{
81		"containerName":     autorest.Encode("path", containerName),
82		"fabricName":        autorest.Encode("path", fabricName),
83		"protectedItemName": autorest.Encode("path", protectedItemName),
84		"recoveryPointId":   autorest.Encode("path", recoveryPointID),
85		"resourceGroupName": autorest.Encode("path", resourceGroupName),
86		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
87		"vaultName":         autorest.Encode("path", vaultName),
88	}
89
90	const APIVersion = "2016-12-01"
91	queryParameters := map[string]interface{}{
92		"api-version": APIVersion,
93	}
94
95	preparer := autorest.CreatePreparer(
96		autorest.AsContentType("application/json; charset=utf-8"),
97		autorest.AsPost(),
98		autorest.WithBaseURL(client.BaseURI),
99		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/recoveryPoints/{recoveryPointId}/provisionInstantItemRecovery", pathParameters),
100		autorest.WithJSON(parameters),
101		autorest.WithQueryParameters(queryParameters))
102	return preparer.Prepare((&http.Request{}).WithContext(ctx))
103}
104
105// ProvisionSender sends the Provision request. The method will close the
106// http.Response Body if it receives an error.
107func (client ItemLevelRecoveryConnectionsClient) ProvisionSender(req *http.Request) (*http.Response, error) {
108	return autorest.SendWithSender(client, req,
109		azure.DoRetryWithRegistration(client.Client))
110}
111
112// ProvisionResponder handles the response to the Provision request. The method always
113// closes the http.Response Body.
114func (client ItemLevelRecoveryConnectionsClient) ProvisionResponder(resp *http.Response) (result autorest.Response, err error) {
115	err = autorest.Respond(
116		resp,
117		client.ByInspecting(),
118		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
119		autorest.ByClosing())
120	result.Response = resp
121	return
122}
123
124// Revoke revokes an iSCSI connection which can be used to download a script. Executing this script opens a file
125// explorer
126// displaying all recoverable files and folders. This is an asynchronous operation.
127// Parameters:
128// vaultName - the name of the recovery services vault.
129// resourceGroupName - the name of the resource group where the recovery services vault is present.
130// fabricName - fabric name associated with the backed up items.
131// containerName - container name associated with the backed up items.
132// protectedItemName - backed up item name whose files/folders are to be restored.
133// recoveryPointID - recovery point ID which represents backed up data. iSCSI connection will be revoked for
134// this backed up data.
135func (client ItemLevelRecoveryConnectionsClient) Revoke(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, recoveryPointID string) (result autorest.Response, err error) {
136	req, err := client.RevokePreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, recoveryPointID)
137	if err != nil {
138		err = autorest.NewErrorWithError(err, "backup.ItemLevelRecoveryConnectionsClient", "Revoke", nil, "Failure preparing request")
139		return
140	}
141
142	resp, err := client.RevokeSender(req)
143	if err != nil {
144		result.Response = resp
145		err = autorest.NewErrorWithError(err, "backup.ItemLevelRecoveryConnectionsClient", "Revoke", resp, "Failure sending request")
146		return
147	}
148
149	result, err = client.RevokeResponder(resp)
150	if err != nil {
151		err = autorest.NewErrorWithError(err, "backup.ItemLevelRecoveryConnectionsClient", "Revoke", resp, "Failure responding to request")
152	}
153
154	return
155}
156
157// RevokePreparer prepares the Revoke request.
158func (client ItemLevelRecoveryConnectionsClient) RevokePreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, recoveryPointID string) (*http.Request, error) {
159	pathParameters := map[string]interface{}{
160		"containerName":     autorest.Encode("path", containerName),
161		"fabricName":        autorest.Encode("path", fabricName),
162		"protectedItemName": autorest.Encode("path", protectedItemName),
163		"recoveryPointId":   autorest.Encode("path", recoveryPointID),
164		"resourceGroupName": autorest.Encode("path", resourceGroupName),
165		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
166		"vaultName":         autorest.Encode("path", vaultName),
167	}
168
169	const APIVersion = "2016-12-01"
170	queryParameters := map[string]interface{}{
171		"api-version": APIVersion,
172	}
173
174	preparer := autorest.CreatePreparer(
175		autorest.AsPost(),
176		autorest.WithBaseURL(client.BaseURI),
177		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/recoveryPoints/{recoveryPointId}/revokeInstantItemRecovery", pathParameters),
178		autorest.WithQueryParameters(queryParameters))
179	return preparer.Prepare((&http.Request{}).WithContext(ctx))
180}
181
182// RevokeSender sends the Revoke request. The method will close the
183// http.Response Body if it receives an error.
184func (client ItemLevelRecoveryConnectionsClient) RevokeSender(req *http.Request) (*http.Response, error) {
185	return autorest.SendWithSender(client, req,
186		azure.DoRetryWithRegistration(client.Client))
187}
188
189// RevokeResponder handles the response to the Revoke request. The method always
190// closes the http.Response Body.
191func (client ItemLevelRecoveryConnectionsClient) RevokeResponder(resp *http.Response) (result autorest.Response, err error) {
192	err = autorest.Respond(
193		resp,
194		client.ByInspecting(),
195		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
196		autorest.ByClosing())
197	result.Response = resp
198	return
199}
200